mysql_num_rows($rs) is returning 1 on all queries.
Correct me if I'm wrong but isn't $rs in this case simply a 'raw dump' of the query and mysql_fetch_assoc 'splits' it into a usable array?
Main Topics
Browse All TopicsI'm using the query below and the query itself is working fine. The contents of the results is working as expected.
What's not working is the count. I get different count results if I run the query in a web page and then the same query in mySQL Administrator.
What I'm trying to do here is have the output do something different when it gets to the last item in the recordset. But I can't seem to get the count correct.
Perhaps there is a different method all together?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>mysql_num_rows($rs) is returning 1 on all queries.
Actually, it is expected to be a "resource id". However it will look like a "1" or TRUE if the query succeeded, as opposed to a "0" or FALSE if the query failed.
Use var_dump($rs) to see what it looks like.
Either of these methods should get you a count of rows in the results set, put into the variable $num. Note that this may not be the same as the number of rows in the table(s), if you use a WHERE or LIMIT clause to down-select from the total rows available.
HTH, ~Ray
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-04-11 at 05:36:03ID: 24121817
mysql_fetch_assoc returns an array of the first row, so count() of that returns the number of columns, and not the number of rows
Select allOpen in new window