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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Why do I only get 1 row for mysql_num_rows?

    I'm not getting the correct number of rows. I only ever get one row.

    Here's the query.Queries are stored in an array.
    PHP Code:
    if( is_array$_POST['waterway'] ) ) {
      foreach(
    $_POST['waterway'] as $value) { 
        
    $queries[count($queries)] = 
          
    mysql_query("SELECT email FROM ehousebo WHERE waterway='$value'"$link);
      } 

    Then I loop through the queries and count the rows for each:
    PHP Code:
    for ($i 0$i count($queries); $i++) {
      for(
    $j 0$j count(mysql_num_rows($queries[$i])); $j++) {
        
    $email_addresses[count($email_addresses)] = mysql_result($queries[$i], $j);
      }

    I only ever get one row for queries that should have multiple rows.
    PHP Code:
    echo count(mysql_num_rows($queries[0])); 
    I should get 11 rows for some of my queries. I tested a query by replacing $value with 'Mississippi River' and still got only 1 row. But using the MySQL, monitor I get 11 rows:
    Code:
    mysql> select * from ehousebo where waterway="Mississippi River";
    Why do I only get 1 row for mysql_num_rows?

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's why:

    PHP Code:
    count(mysql_num_rows($queries[$i])) 
    Trying to count a number. count() counts array length.

    What I did was: count(11)

    Here's the doc for count:
    http://us3.php.net/manual/en/function.count.php

    Description
    int count ( mixed var [, int mode])

    Returns the number of elements in var, which is typically an array (since anything else will have one element).

    If var is not an array, 1 will be returned (exception: count(NULL) equals 0).
    Most other languages have collection or array methods like array.length, or arrayList.size(). With PHP, there is a count function that can accept null or mixed var.

    I find this counterintuitive and inelegant.


  •  

    Posting Permissions

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