corillo181 Posted September 23, 2007 Share Posted September 23, 2007 why is this returning only 1 record when i got 10? <?php $query = "SELECT * FROM artist ORDER BY name"; $result = $db->query($query); $Info = $db->fetch_array($result); echo '<pre>'; print_r($Info); echo '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/ Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 because you only fetch_array once. Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353550 Share on other sites More sharing options...
teng84 Posted September 23, 2007 Share Posted September 23, 2007 show the function for that fetch array Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353617 Share on other sites More sharing options...
corillo181 Posted September 23, 2007 Author Share Posted September 23, 2007 it does not matter if i fetch once, the print_r is just going to show whats in the array.. inside the fetch_array function is only the real function. plus i know it works because i use it for all my work. function fetch_array($query){ return mysql_fetch_array($query); } Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353624 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 mysql_fetch_array() only returns one row of data (one record). so if you only call it once, you only get one record. Try this: while ($Info = $db->fetch_array($result)) { echo '<pre>'; print_r($Info); echo '</pre>'; } and if that doesn't work, pull the mysql_fetch_array() function out of fetch_array(). kind of silly to save typing mysql_ a few times: while ($Info = mysql_fetch_array($result)) { echo '<pre>'; print_r($Info); echo '</pre>'; } Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353627 Share on other sites More sharing options...
trq Posted September 23, 2007 Share Posted September 23, 2007 You need to loop through your results. <?php $query = "SELECT * FROM artist ORDER BY name"; $result = $db->query($query); while ($Info = $db->fetch_array($result)) { echo '<pre>'; print_r($Info); echo '</pre>'; } ?> Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353628 Share on other sites More sharing options...
teng84 Posted September 23, 2007 Share Posted September 23, 2007 function fetch_array($query){ while($resut=mysql_fetch_array($query){ $value[] =$resut; } return $value; } Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353637 Share on other sites More sharing options...
corillo181 Posted September 23, 2007 Author Share Posted September 23, 2007 i did added the while loop and it stills only show me one profile. and is not silly to not want to write mysql a few time if you can see is a class that i'm using so there is no need for the whole thing. Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353663 Share on other sites More sharing options...
trq Posted September 23, 2007 Share Posted September 23, 2007 i did added the while loop and it stills only show me one profile. Then there is only one record. Post your current code. Link to comment https://forums.phpfreaks.com/topic/70377-problem-with-query/#findComment-353665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.