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!! Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/52357-creating-a-loop/#findComment-258377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.