Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: count results?

  1. #11
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I often use:
    Code:
    $query = "SELECT * FROM table";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
    for ($i = 0;$i < $num;$i++)
      $fields = mysql_result($result,$i,"myfield");
    mysql_num_rows returns the number of rows anyways.
    - Mike

  2. #12
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mburt View Post
    Shouldn't it be:
    Code:
    for($resultnumber = 1; $iddrow = count(mysql_fetch_array($iddrs)); ++$resultnumber)
    Seeings it returns an array?
    the count seemed to work.. but it just created 15000 results, which were all the same.. then firefox crashed!

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Haha, whoops -- I think it should have been
    Code:
    for($resultnumber = 1; $iddrow = mysql_fetch_array($iddrs); ++$resultnumber)
    I didn't really look, just inserted code around what was already there
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    So calling the array directly will give you it's length?
    - Mike

  5. #15
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    twey, is that not the same code you posted before?!

    I didnt know where to put it, so i tried before, then after the while statement.. but both just show 1 as the result..

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Like this:
    Code:
    <?php 
      $iddaddress = "localhost"; 
      $iddusername = "xxxx"; 
      $iddpassword = "xxxx"; 
      $idddb = "xxxx"; 
      $iddconn = mysql_connect($iddaddress, $iddusername, $iddpassword); 
      $iddrs = mysql_select_db($idddb, $iddconn); 
      $iddsql="SELECT * FROM handset GROUP BY handset"; 
      $iddrs = mysql_query($iddsql, $iddconn); 
    
      for($resultnumber = 1; $iddrow = mysql_fetch_array($iddrs); ++$resultnumber) {
        $iddmake = $iddrow['make']; 
        $iddhand = $iddrow['handset']; 
        $idddetails = $iddrow['details']; 
     
        echo("This is result number: $resultnumber");
      }
      mysql_close(); 
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #17
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thanks twey and everyone else!! works great!

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
  •