Jump to content

Why am I getting No results?


SalientAnimal

Recommended Posts

Hi All,

 

I am runningt his query to count and then display the current date's records captured. Even thoguh I know there are records captured, why am I still getting no results?

 

$result = mysql_query("SELECT * FROM cs_2012
WHERE 
sys_date = CURRENT_DATE()");
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

Link to comment
https://forums.phpfreaks.com/topic/264727-why-am-i-getting-no-results/
Share on other sites

If you're getting no results then there aren't any records being "captured". Try running your query using some tool like phpMyAdmin or MySQL Workbench.

 

 

I've run the query using a like function and then using today's date and I am getting results, however, I don't want to have to update the query everyday.

 

$result = mysql_query("SELECT * FROM cs_2012WHERE sys_date = like '2012-06-25%'");$num_rows = mysql_num_rows($result);echo "$num_rows Rows\n";

 

The above query returns 270 Rows. But when using CURDATE() or CURRENT_DATE() it says 0 Rows

Ok, so I finally after lots of trial nad error got this to work.

 

I can only assume that the reason I wasn't getting any results is because my sys_date column is a TIMESTAMP field.

 

Here's the solution:

 

$result = mysql_query("
SELECT * FROM cs_2012
WHERE 
DATE(sys_date) = CURDATE()
");
$num_rows = mysql_num_rows($result);

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.