|
Posted by BKDotCom on 11/20/06 22:55
I created a function get_query_rows() that makes the repetitive task of
using mysql_query() and looping through abnd getting the results easier
(for me anyhow).
$arr = array ("A", "B", "C", "D", "E");
foreach ($arr as $client)
{
$query = 'SELECT COUNT(*) as count from table where columnA =
"'.$client.'"';
$rows = get_query_rows($query);
$count = $rows[0]['count'];
echo "$client has $count<BR />";
}
function get_query_rows($query,$resource=null)
{
$rows = false;
$result = ( $resource )
? @mysql_query($query,$resource)
: @mysql_query($query);
if ( $result )
{
$rows = array();
$num_rows = mysql_num_rows($result);
for ( $i=0; $i<$num_rows; $i++ )
$rows[] = mysql_fetch_assoc($result);
}
else
trigger_error(mysql_error());
return $rows;
}
[Back to original message]
|