You are here: finding data in an array « PHP Programming Language « IT news, forums, messages
finding data in an array

Posted by windandwaves on 01/14/06 11:24

Hi Folk

I have the following function:

function getdata($sql) {
$result = @mysql_query($sql) or die("Error: " . mysql_error()." sql was
".$sql);
$ret = array();
while($row = mysql_fetch_assoc($result)) {
$ret[] = $row;
}
mysql_free_result($result);
return $ret;
}

I love it, because all I need to do is to stick in some sql (e.g. Select *
from clients) and away she goes like this

$sql = "SELECT * FROM CLIENTS;"
$data = getdata($sql)
foreach($data as $ds) {
echo '<p>'. $ds["first_name"].' '.$ds["first_name"].'</p>';
}

Now, what I want to do is check the fields for all $ds arrays. That is, I
want to check one particular field for all the "rows" and check that it is
identical.

What is the most efficient way to do this? Is there a function that I can
use? Something like

function datafieldcheck($ma, $fld) {
//$ma = a multidimensional array from the getdata function
//$fld = the field to check
foreach($multiarray as $ds) {
$v = $ds[$fld];
if(!$first) {
if ($v != $vex) {
return false;
}
}
$vex = $v;
$first = 1;
}
return true;
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация