Jump to content

[SOLVED] help with foreach


dadamssg

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.