#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    With this query:

    SELECT * FROM tablename WHERE data='somedata'

    What would I do to create a variable that would store the number of records the query matched?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    $result = mysql_query("SELECT * FROM tablename WHERE data='somedata'", $db);

    $count = mysql_num_rows($result);

    No $count hold sthe number of records found

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    15
    or
    $query = "SELECT count(*) FROM Tablename WHERE Data='$data'";
    $result = mysql_query($query);

    I different approach - both work though
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    or
    $query = "SELECT count(*) FROM Tablename WHERE Data='$data'";
    $result = mysql_query($query);
    >>


    The sql query should be something like..

    $query = "SELECT count(*) as a FROM Tablename WHERE Data='$data'";

    $result = mysql_query($query);

    $row=mysql_fetch_array($result);
    echo $row["a"];

    ------------------------


    $count = mysql_num_rows($result);

    This way is very easy...




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. Overwriting mysql query with the query results
    By onerandomday in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 05:45 AM
  2. counting amount of rows within a query
    By JasonL in forum MySQL Help
    Replies: 4
    Last Post: December 29th, 2003, 01:42 PM
  3. Syntax error in INSERT INTO query
    By Lee Miles in forum Visual Basic Programming
    Replies: 6
    Last Post: December 19th, 2003, 08:37 AM
  4. nested query and MySQL query
    By lucipher in forum MySQL Help
    Replies: 1
    Last Post: November 19th, 2003, 11:49 AM
  5. extremely inconsistent query times
    By mtnman in forum MySQL Help
    Replies: 0
    Last Post: October 23rd, 2003, 01:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo