Jump to content

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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.