textbox Posted May 21, 2007 Share Posted May 21, 2007 Hello, i wish to create a loop to pull all the information out of my table, instead of just one line. <?php //query the database for the comments for this user $sql = "SELECT * FROM `comments` WHERE `to` = '$username'"; $result = mysql_query($sql) OR die(mysql_error()); $num=mysql_num_rows($result); $from=mysql_result($result,0,"from"); $to=mysql_result($result,0,"to"); $comment=mysql_result($result,0,"comment"); $spacer = " - "; $printcomments = "$from$spacer$comment"; Any help would be great!! Link to comment https://forums.phpfreaks.com/topic/52357-creating-a-loop/ Share on other sites More sharing options...
chigley Posted May 21, 2007 Share Posted May 21, 2007 This is the code to output multiple database entries with a loop. <?php $query = mysql_query("SELECT * FROM table WHERE id = 1"); while($row = mysql_fetch_assoc($query)) { echo "ID: $row['id']<br />Name: $row['name']<br /><br />"; } ?> Can be adapted to suit your needs Link to comment https://forums.phpfreaks.com/topic/52357-creating-a-loop/#findComment-258377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.