SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?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/>\n";
    ?>
    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.

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    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.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    (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)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •