|
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]
|