Jump to content

php not behaving like phpmyadmin?


reakt

Recommended Posts

Hi Guys, this one is driving me mental. What have I done wrong?

 

$itemId = '3806';

$sql4 = mysql_query("SELECT Recurring_Charges.serviceType, Recurring_Charges.description, Recurring_Charges.period, Recurring_Charges.amount, Service_Groups.name
FROM Recurring_Charges, Service_Groups, Hosting_Services
WHERE Hosting_Services.id = Recurring_Charges.serviceId
AND Service_Groups.id = Hosting_Services.groupId
AND Recurring_Charges.invoiceItemId ='$itemId'
");

$num_rows = mysql_num_rows($sql4);
echo "num_rows is $num_rows<br />\n";
while ($result4 = mysql_fetch_array($sql4)) {
echo "got a result<br />\n";
print_r($result4);
}

 

Output is simply:

 

num_rows is

 

When I copy and paste the same query into phpmyadmin I get a proper result. Why doesn't it work and why don't I get an error or even 0 row count? Thanks

Link to comment
https://forums.phpfreaks.com/topic/239401-php-not-behaving-like-phpmyadmin/
Share on other sites

well if it is exactly the same it should be al right. But do you have a connection with the database? Do you get any error?

place this above your script

error_reporting(E_ALL);
ini_set("display_errors", 1);

I have a connection with the db, just didn't want to copy it in for security reasons. To prove the connection is ok, I added another query before the offending one, which works fine. I added your error reporting bit too and now I get a warning:

 

$sql = mysql_query("SELECT * FROM Recurring_Charges");
$num_rows1 = mysql_num_rows($sql);

echo "num_rows1 is $num_rows1<br />\n";

$itemId = '3806';

$sql4 = mysql_query("SELECT Recurring_Charges.serviceType, Recurring_Charges.description, Recurring_Charges.period, Recurring_Charges.amount, Service_Groups.name
FROM Recurring_Charges, Service_Groups, Hosting_Services
WHERE Hosting_Services.id = Recurring_Charges.serviceId
AND Service_Groups.id = Hosting_Services.groupId
AND Recurring_Charges.invoiceItemId = '$itemId'");

$num_rows = mysql_num_rows($sql4);
echo "num_rows is $num_rows<br />\n";
while ($result4 = mysql_fetch_array($sql4)) {
echo "got a result<br />\n";
print_r($result4);
}

 

Returns:

 

num_rows1 is 2426

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /var/websites/something/www/test.php on line 29

num_rows is

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /var/websites/something/www/test.php on line 31

 

The variable it's referring to is obviously $sql4, but why does it think it's a boolean? As stated when I copy and paste the exact statement into phpmyadmin and change $itemId to 3806 I get a proper result containing 1 row.

I apologise for wasting your time guys. I've just realized I was running my php script on one mysql installation, and testing the query in phpmyadmin on another installation. They are supposed to be the same, but I just found the table Service_Groups doesn't exist on the dev installation. Once again, sorry!  :facewall:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.