Forum Moderators: coopster
I am executing the following query from PHP code, using mysql_fetch_array(mysql_query()) functions,
$sql = "SELECT count(br.bname) as cc
FROM beers br, brewers bw
WHERE br.bid = bw.bwid
AND br.sid = '$style'";
echo $sql;
$brRes = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($brRes);
echo $row['cc'];
I get 2 rows from last echo...
however if i execute the very same query directly in phpmyadmin i get 15 rows.
i have tested this for many different values and always get less rows from PHP and more rows from phpmyadmin.
Can anybody shed some light please what's going wrong with this?
thank you very much.
$brRes = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($brRes);
echo count($row);
echo $sql;
my echo count() line shows 18 as the result rows. however, i copy the query which i get from echo $sql and paste it in the phpmyadmin and get 364 results.
the AND section is not giving problem, because i am not changing anything in the query, i execute the very same query in phpmyadmin.
i am lost :( ....
Finally I have fixed the problem. It had to do with my hosting server setup. I am not sure about the details but somehow the code was connecting to the wrong database. I had a sample and a working database. Sample database has less records for testing and production database is huge. Phpmyadmin was communicating with production database while the php code was working with sample database.
I saw a mysql server problem notice on the hosting company side, and as soon as they fixed it the code started to work fine.
Thank you all for your help.