Jump to content

Recommended Posts

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.