View Full Version : Why do I only get 1 row for mysql_num_rows?

DHTML Kitchen
03-31-2004, 01:57 PM
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.

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:

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.

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:

mysql> select * from ehousebo where waterway="Mississippi River";

Why do I only get 1 row for mysql_num_rows?

DHTML Kitchen
03-31-2004, 03:13 PM
Here's why:


Trying to count a number. count() counts array length.

What I did was: count(11)

Here's the doc for count:

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.