Hello,

Im a little bit confused with this piece of coding I have!

Im basically trying to add a script I have converted to a web page! The original code was using echo statements which was fine on a separate page but now I want it to be apart of my profile pages.

Here is the code:

$getComment = fetch("SELECT * FROM members_comments WHERE post_to ='$user' AND game='$game'");


//Retrieves data from MySQL 
$data = mysql_query("SELECT * FROM members_comments WHERE post_to = '$members_profiles[username]' ") or die(mysql_error()); 
//Puts it into an array 
while($info = mysql_fetch_array( $data )) 
{ 
//Outputs the image and other data
$comments ="


<br>Comment</b> ".$info['post_message']."<br>
<br>By:</b> ".$info['post_by']."<br>

<b>Sent On:</b> ".$info['timestamp']."<p> 
<hr color=\"#008000\" width=\"300\">

" ;


}

Now by using the current code it DOES show the contents from the mysql but only shows ONE result! I would like it to show all results from the mysql.

My guess is I have mucked up the WHILE bit which is the bit thats meant to repeat it isnt it?

This is the original code when not integrated into my web page and it collects all field results from the mysql table and not jut the one.

//Retrieves data from MySQL 
$data = mysql_query("SELECT * FROM members_comments WHERE post_to = '$members_profiles[username]' ") or die(mysql_error()); 
//Puts it into an array 
while($info = mysql_fetch_array( $data )) 
{ 



//Outputs the image and other data
echo "<br>Comment</b> ".$info['post_message']."<br>";
echo "<br>By:</b> ".$info['post_by']."<br>";

 echo "<b>Sent On:</b> ".$info['timestamp']."<p> 
<hr color=\"#008000\" width=\"300\">" ;

Id apreciate any help!

Thank you

Justin

Recommended Answers

All 3 Replies

hi ,

$getComment = fetch("SELECT * FROM members_comments WHERE post_to ='$user' AND game='$game'");

what this line means and what is work of fetch function

also,
use here

while($info = mysql_fetch_assoc( $data ))

instead of

while($info = mysql_fetch_array( $data ))

one more

$data = mysql_query("SELECT * FROM members_comments WHERE post_to = '$members_profiles[username]' ") or die(mysql_error());

use

$data = mysql_query("SELECT post_message,timestamp FROM members_comments WHERE post_to = '$members_profiles[username]' ") or die(mysql_error());

try and reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.