Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Hello, I know some code for counting all the rows of a table

    Code:
    $sql = "SELECT * FROM wplanet_freestuff";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    echo "$num";
    How can I change it to count only the rows which were added the day a visitor came (I mean to get visitor's date and tell " today added : 2 for instance)

    Thanks in advance ...
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    First of all, you should be doing it like this (much faster):
    PHP Code:
    $sql "SELECT COUNT(*) AS stuff_count FROM wplanet_freestuff";
    $result mysql_query($sql);
    $row mysql_fetch_array$queryMYSQL_ASSOC );
    echo 
    $row['stuff_count']; 
    You can limit your stuff at the db to today's records like so:
    PHP Code:
    $sql "SELECT COUNT(*) AS stuff_count FROM wplanet_freestuff 
            WHERE TO_DAYS(date_column) = TO_DAYS(CURDATE())"
    ;
    $result mysql_query($sql);
    $row mysql_fetch_array$queryMYSQL_ASSOC );
    echo 
    $row['stuff_count']; 
    I think that should work (not 100% sure). Anyone else want to help out?

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    SELECT COUNT(*) is only blindingly fast for no WHERE clause. When there is one, it should be COUNT(uniquecolumn).
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    True dat. Good point. (can't believe I made that mistake, lol)

  6. #5
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Thanx, I will give it a try
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:08 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com