PDA

View Full Version : I am getting a blank page/no error with this code:


Doc203
08-25-2004, 12:50 PM
I am learning php and I am trying to get this php script to return a result when called by a browser. Can someone look at it and give me a hand?

$start_date = "2004-08-01 00:00:00";
$end_date = "2004-08-23 00:00:00";

$result = $DB_site->query("SELECT COUNT(post.postid) AS count, user.username
FROM post
LEFT JOIN user ON (user.userid = post.userid)
AND (UNIX_TIMESTAMP('$start_date')) <= post.dateline
AND post.dateline <= (UNIX_TIMESTAMP('end_date'))
GROUP BY user.userid ORDER BY count DESC, username");

Xenon
08-26-2004, 06:38 AM
(UNIX_TIMESTAMP('end_date'))

you've missed a $ before end_date ;)

Doc203
08-26-2004, 04:02 PM
Thanks Xenon, I have added a line also so I could find out a little more and here is what I get now:

"I failed and here is why: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #14' at line 1
"

If I run the query directly in Mysql it returns the results correctly. Any ideas? Thanks for the help!


<?PHP
require("./global.php");

$start_date = "2004-08-01 00:00:00";
$end_date = "2004-08-23 00:00:00";

$stmt = $DB_site->query("SELECT COUNT(post.postid) AS count, user.username
FROM post
LEFT JOIN user ON (user.userid = post.userid)
AND (UNIX_TIMESTAMP('$start_date')) <= post.dateline
AND post.dateline <= (UNIX_TIMESTAMP('$end_date'))
GROUP BY user.userid ORDER BY count DESC, username");

$sr = mysql_query($stmt) or die ("<p>I failed and here is why: " . mysql_error());

?>

Xenon
08-27-2004, 02:01 PM
$DB_site->query already calls mysql_query, so $stmt contains already the mysql result, and therefore you cannot put it as argument of mysql_query again :)

Doc203
08-28-2004, 02:26 PM
Thanks Xenon, not only did that help solve my problem, but I understand better as well!

Xenon
08-28-2004, 03:17 PM
:) glad i could help