Forum Moderators: coopster
I wanted to output content from a MySQL table by an id. The id column is an auto_increment, so each value should be unique.
I also wanted to pull how many rows were returned by my query. Ideally there should be only 1 row pulled, but I would imagine 0 rows would be pulled if there wasn't a row with a matching id.
I used mysql_affected_rows to count the number of rows queried, and it seems to work but I'm hesitant. PHP.net says that mysql_affected_rows "Get[s] the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query..." I'm doing none of these operations.
I'm worried that just because its working for me and my sample set right now, it may be problematic in the future.
Is there a more appropriate way to count the number of rows queried?
Thank you for your input.
$data=mysql_fetch_array(mysql_query("SELECT * FROM table WHERE id='$id'"));
$rows=mysql_affected_rows();
I liked how the mysql command seemed specific for what I wanted, and not seemingly workaround like count, but when I tried mysql_num_rows I get an error of:
Wrong parameter count for mysql_num_rows(), I get the error "Wrong parameter count for mysql_num_rows()" with no rows counted at all.
Might I be misusing this?
Thanks