dadamssg Posted March 28, 2009 Share Posted March 28, 2009 im pulling replies out of my db to display so i want to display them each in their own table. Not real sure how to setup up the foreach loop though. heres what i have //get replies $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Couldn't connect"); $quu = "SELECT * FROM Replies WHERE postid = $postid ORDER BY time DESC"; $res = mysqli_query($cxn,$quu) or die ("Couldn't execute"); $ric = mysqli_fetch_assoc($res); and then my attempt at the loop foreach($ric){ echo "<center><table border=7>"; echo "<tr><td>Reply Id:</td><td>{$ric['replyid']}</td></tr>"; echo "<tr><td>Posted:</td><td>{$ric['time']}</td></tr>"; echo "<tr><td>Posted By:</td><td>{$ric['createdby']}</td></tr>"; echo "<tr><td>Reply:</td><td>{$ric['reply']}</td></tr>"; echo "</center></table><br><br>"; } im getting an unexpected ( on that first line of the foreach. Link to comment https://forums.phpfreaks.com/topic/151476-solved-help-with-foreach/ Share on other sites More sharing options...
dadamssg Posted March 28, 2009 Author Share Posted March 28, 2009 i figure it out sort of still having a weird problem though.. im using this //get replies $quu = "SELECT * FROM Replies WHERE postid = $postid ORDER BY time DESC"; $res = mysqli_query($cxn,$quu) or die ("Couldn't execute"); while($ric = mysqli_fetch_assoc($res)){ echo "<center><table border=7>"; echo "<tr><td>Reply Id:</td><td>{$ric['replyid']}</td></tr>"; echo "<tr><td>Posted:</td><td>{$ric['time']}</td></tr>"; echo "<tr><td>Posted By:</td><td>{$ric['createdby']}</td></tr>"; echo "<tr><td>Reply:</td><td>{$ric['reply']}</td></tr>"; echo "</center></table><br><br>"; } the time is when that reply was posted....when i go to the page it pulls up all the replies EXCEPT the very latest one...but when i copy and paste the query in phpMyadmin i get what im suppose to. does anybody have a clue whats going on? Link to comment https://forums.phpfreaks.com/topic/151476-solved-help-with-foreach/#findComment-795620 Share on other sites More sharing options...
dadamssg Posted March 28, 2009 Author Share Posted March 28, 2009 hmmm i cut off the ORDER BY in the query and i figured its not outputting the very first row of data it pulls up...for whatever reason...ideas? Link to comment https://forums.phpfreaks.com/topic/151476-solved-help-with-foreach/#findComment-795623 Share on other sites More sharing options...
dadamssg Posted March 28, 2009 Author Share Posted March 28, 2009 figured it out...i was defining this twice like so and for whatever reason that takes off the first row of data $ric = mysqli_fetch_assoc($res); while($ric = mysqli_fetch_assoc($res)){ so i just deleted the first line and it works Link to comment https://forums.phpfreaks.com/topic/151476-solved-help-with-foreach/#findComment-795626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.