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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

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

Post 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();
 
?>
 
Last edited by Weirdan on Fri Jun 26, 2009 12:03 pm, edited 2 times in total.
Reason: added [code] tags
User avatar
juma929
Forum Commoner
Posts: 72
Joined: Wed Jun 17, 2009 9:41 am

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

Post 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.
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

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

Post 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.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

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

Post 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");
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

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

Post by phillyrob »

Thx Darhazer , that was it. I appreciate it.
Post Reply