Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post counting results from a mysql database

    Hi, i have a mysql database and a php script that uses that.

    I want to know how many results throw a query in order to know if they have reached a limit.

    I.E.
    Code:
         $sql = mysql_query ("select * from classifieds where user='$username'");
    while ($row = mysql_fetch_array($sql))
    {
    }
    I want to check lets say that only 10 classifieds per 'username' can be created.

    If ten or more classifieds are in the database for that 'username' then show error message.

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    mysql_num_rows will help

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep, mysql_num_rows is what you need.

    $sql = mysql_query ("select * from classifieds where user='$username'");
    $my_count = mysql_num_rows($sql);
    if ($my_count >= 10)
    {
    //put your error message
    }


  •  

    Posting Permissions

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