onedumbcoder Posted May 20, 2008 Share Posted May 20, 2008 if i have $result = mysql_query("...") and i keep doing $list = mysql_fetch_array($result ); echo $list['name'] $list = mysql_fetch_array($result ); echo $list['name'] $list = mysql_fetch_array($result ); echo $list['name'] what will happen if there is no more elements left? will it through an exception? and is there a way to check if there is any more elements left for example if(mysql_has_next($result)) Link to comment https://forums.phpfreaks.com/topic/106463-question-about-getting-query-elements/ Share on other sites More sharing options...
soycharliente Posted May 20, 2008 Share Posted May 20, 2008 Use a while loop. It will automatically stop processing once the elements run out. From the manual: array mysql_fetch_array ( resource $result [, int $result_type ] ) Returns an array that corresponds to the fetched row and moves the internal data pointer ahead. It knows. <?php $result = mysql_query("..."); if (mysql_num_rows($result) > 0) { while ($list = mysql_fetch_array($result)) { echo $list['name']; } } ?> Link to comment https://forums.phpfreaks.com/topic/106463-question-about-getting-query-elements/#findComment-545701 Share on other sites More sharing options...
onedumbcoder Posted May 20, 2008 Author Share Posted May 20, 2008 i cant use a while loop for what i need it for, i need to iterate through it manually. Link to comment https://forums.phpfreaks.com/topic/106463-question-about-getting-query-elements/#findComment-545706 Share on other sites More sharing options...
jonaHill87 Posted May 20, 2008 Share Posted May 20, 2008 what exactly are you trying to do? find a specific value or echo all of the values in the array? Link to comment https://forums.phpfreaks.com/topic/106463-question-about-getting-query-elements/#findComment-545743 Share on other sites More sharing options...
soycharliente Posted May 20, 2008 Share Posted May 20, 2008 i cant use a while loop for what i need it for, i need to iterate through it manually. Can you explain a bit more of what you're trying to do? Link to comment https://forums.phpfreaks.com/topic/106463-question-about-getting-query-elements/#findComment-545783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.