Display Row Count created today

Hi guys

New to PHP and MySQL etc.

I have a database table called “packages-table” with the following columns
sender, recipient, date_time, mail_type

I’ve successfully managed to display the total number of rows in the database table using the following

<?php
// Amout of Items for all time
$result = mysql_query("SELECT * FROM packages-table", $link);
$num_rows = mysql_num_rows($result);

echo "<strong>$num_rows</strong> Packages logged so far <br/><br/>\
";
?>

Can anyone tell me how I would display the total number of rows for today?
Note: “Today” is relative and would be the day a user is looking at the report as opposed to a specific date.

Please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn’t tie you down so much to a particular database server software.

Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.

(The obligatory warning out of the way…)
WHERE clause will be your solution.

Something like WHERE date = CURRENT_DATE (without your table schema, i cant be more precise.)

Also, simplify your statement.

SELECT COUNT(date) FROM packages-table WHERE date = CURRENT_DATE;

This will result in mysql only needing to send back a single value (the count), as opposed to the full entry for every row in the table. (much smaller transfer)