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