Jump to content

How to Loop a Query


Smee

Recommended Posts

Hey All,

 

I'm new to PHP and was wondering if someone could help me out.

 

Im currently creating a friends list that shows added friends to users that are logged in.

 

<?php

 

$result = mysql_query ("SELECT * FROM friends WHERE me = '$username'");

 

($row = mysql_fetch_array($result));

 

echo " <b>Username:</b> $row[friend] </br> ";

 

?>

 

Above is the query i created that shows my freinds but because of the setup of SQL database i am only getting one result showing.

 

SQL database is setup like this:

 

      me          friend

 

  username  friendsusername

 

When multiple usernames are the same it only shows the most current friend when displayed on my main page.

 

I have tried to do some while loops but to no avail. Bascally i just need to keep it as simple as possible but display all friends under a certain username.

 

Thanks for any help

 

Smee

Link to comment
https://forums.phpfreaks.com/topic/145777-how-to-loop-a-query/
Share on other sites

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.