Page 1 of 1

Why this works on MYSQL command line but not in php?

Posted: Fri Jun 26, 2009 8:15 am
by phillyrob
I don't have a clue as to why this does not work in php, but it does, when I copy and paste the select statement directly into the mysql command line. I get a blank screen when I run this on php; I connect to the db successfully. Can anyone tell me why it would not show?


Code: Select all

 
<?php
 
include ('connect_db.php');
function selectfrom()
{
 
$rs7 = mysql_query ("SELECT item1, COUNT(item1) from products where Date > DATE_ADD(CURDATE(), INTERVAL -25 DAY group by item1)");
while($row7 = mysql_fetch_array($rs7))
{
echo $row7['item1']." ".$row7['COUNT(item1)']."<br>";
 
}
 
}
 
selectfrom();
 
?>
 

Re: Why this works on MYSQL command line but not in php?

Posted: Fri Jun 26, 2009 8:43 am
by juma929
Hello,

Im not in a position to test your code at the moment, but are you sure it is error free? Sometimes if error reporting is disabled completely you will get a blank page if an error occurs. Try turning on error reporting. In your code include ('connect_db.php') needs to be include ('connect_db.php'); you just missed a semi colon, that also could be your problem.

Thanks.

Re: Why this works on MYSQL command line but not in php?

Posted: Fri Jun 26, 2009 10:58 am
by phillyrob
Thanks for the reply juma929, I left that semicolon off during the copy paste, it is there on the actual code. It does connect to database just fine. I will take you advice and add error coding. Thx again.

Re: Why this works on MYSQL command line but not in php?

Posted: Sat Jun 27, 2009 3:38 pm
by Darhazer
Are you sure you are executing exactly the same SQL in the command line?
It seems that the ) should be closed before GROUP BY:

Code: Select all

 
s7 = mysql_query ("SELECT item1, COUNT(item1) from products where Date > DATE_ADD(CURDATE(), INTERVAL -25 DAY) group by item1");

Re: Why this works on MYSQL command line but not in php?

Posted: Sun Jun 28, 2009 9:17 am
by phillyrob
Thx Darhazer , that was it. I appreciate it.