WRXHokie Posted March 28, 2007 Share Posted March 28, 2007 I'm trying to do a query on my database in a php script in which i take a integer value from a form and then check it against a table in my database. The integer value is a unique id for a person table, so there is only one id for each person in the table. Thus a query on the table such as "SELECT * FROM $db.person WHERE id = 3" should return only one row. But it is in fact returning multiple rows. I've checked my database... its setup correctly with 11 people in it... each with a unique id from 1-11. Here's my php code: $query = "SELECT * FROM $db.person WHERE id = $personid"; $result = mysql_query($query); $r = mysql_fetch_array($result); print count($r); For some reason this query returns a count value of 6 where $personid is set to an integer value from 1-11. Any ideas why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/44716-solved-mysql-returning-multiple-rows-on-single-row-query/ Share on other sites More sharing options...
cmgmyr Posted March 28, 2007 Share Posted March 28, 2007 try doing: $query = "SELECT * FROM $db.person WHERE id = $personid"; $result = mysql_query($query); $count = mysql_num_rows($result); echo $count; see what that does Quote Link to comment https://forums.phpfreaks.com/topic/44716-solved-mysql-returning-multiple-rows-on-single-row-query/#findComment-217103 Share on other sites More sharing options...
WRXHokie Posted March 29, 2007 Author Share Posted March 29, 2007 Nah i figured it out.... i forgot that when you dont specify extra arguments to mysql_fetch_array() it gives you two copies of each row indexed in two different ways. Quote Link to comment https://forums.phpfreaks.com/topic/44716-solved-mysql-returning-multiple-rows-on-single-row-query/#findComment-217121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.