lalnfl Posted April 24, 2011 Share Posted April 24, 2011 $array = array("1","2","3"); foreach ($array as $value){ echo $value; } Put its only echoing out 3, not the whole array. Link to comment https://forums.phpfreaks.com/topic/234557-foreach-loop-not-looping/ Share on other sites More sharing options...
kenrbnsn Posted April 24, 2011 Share Posted April 24, 2011 It should echo "123" Try <?php $array = array("1","2","3"); foreach ($array as $value){ echo $value . '<br>'; } ?> Another way to do this is <?php $array = array("1","2","3"); echo implode('<br>',$array); ?> Ken Link to comment https://forums.phpfreaks.com/topic/234557-foreach-loop-not-looping/#findComment-1205437 Share on other sites More sharing options...
fugix Posted April 24, 2011 Share Posted April 24, 2011 Try printr($array) to see what displays Link to comment https://forums.phpfreaks.com/topic/234557-foreach-loop-not-looping/#findComment-1205445 Share on other sites More sharing options...
lalnfl Posted April 24, 2011 Author Share Posted April 24, 2011 $sql_get_worker = mysql_query("SELECT id FROM Worker WHERE mem_id='$id' AND retired='n'"); $get_worker = mysql_fetch_assoc($sql_get_worker); foreach ($get_worker as $value){ $sql_get_worker = mysql_query("SELECT * FROM Worker WHERE id='$value'"); $get_worker = mysql_fetch_array($sql_get_worker); $worker_firstname = $get_worker['firstname']; $worker_lastname = $get_worker['lastname']; $worker_options .= "<option value='$value'>$worker_firstname $worker_lastname</option>"; } How about this then? There are two rows that return with this id, but yet only one is returning. Link to comment https://forums.phpfreaks.com/topic/234557-foreach-loop-not-looping/#findComment-1205458 Share on other sites More sharing options...
Pikachu2000 Posted April 24, 2011 Share Posted April 24, 2011 Each iteration of mysql_fetch_assoc() only retrieves one record. You need a while() loop if you're expecting the result set to be more than one record. Link to comment https://forums.phpfreaks.com/topic/234557-foreach-loop-not-looping/#findComment-1205460 Share on other sites More sharing options...
lalnfl Posted April 24, 2011 Author Share Posted April 24, 2011 Now I see it. Thanks! Link to comment https://forums.phpfreaks.com/topic/234557-foreach-loop-not-looping/#findComment-1205461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.