I have an idea for a friends list based off a user's account info.

'guid' is the character id number
'account' is the player's account number
'friend' is the player he is friends with
'online' 1 = online; 0= offline

Here's what the layout is like:

Friends List

`character_social` (`guid`, `friend`, `flags`, `note`) VALUES (6, 2, 1, 'Character 1');
`character_social` (`guid`, `friend`, `flags`, `note`) VALUES (2, 6, 1, 'Character 2');

So Character 1 is friends with Character 2 and vice versa.

Character Profiles

`characters` (`guid`, `account`, `name`, `online`) VALUES (6, 7, 'Character 1', 0);
`characters` (`guid`, `account`, `name`, `online`) VALUES (2, 6, 'Character 2', 0);

What i'm trying to do is display the currently logged in user's friends on a page.

So when Character 1 logs in it reads his friends list to find their 'guid' number and then looks to see if the friend is online by checking that friends 'online' field for a 1, if found it displays that characters 'name'.

I have no idea how to do this. Any help would be greatly appreciated.

Thank you.

vedro-compota commented: ++++ +1

Recommended Answers

All 5 Replies

Show us what you have done so far)

Hi mrniceguy,

This is what I have so far;

<?php
mysql_connect("localhost","root","password") OR die(mysql_error());
mysql_select_db("characters") OR die(mysql_error());
$query= mysql_query("SELECT name FROM characters WHERE online ='1' ORDER BY name") OR die(mysql_error());
$query= mysql_query("SELECT guid FROM characters WHERE online ='1' ") OR die(mysql_error());
$query= mysql_query("SELECT friend FROM characters_social WHERE characters.online ='1' ") OR die(mysql_error());

while($row=mysql_fetch_array($query)){
$name = $row['name'];
echo "$name is  Online<br/>";
}

I know it's practically nothing, I have no idea how to connect the currently logged in user to which friends he/she has and fetch them. Crossing different databases and comparing data is something I have yet to figure out.

If you can point me in the right direction I should be able to figure out how this is supposed to work.

Thanks for the reply,
Waffles

/*first do DB connection*/

/*second  get the id of logged in user from session or any method u prefer.*/
$guid=$_SESSION['guid'];
$query= mysql_query("SELECT friend FROM characters_social WHERE guid='$guid' ") OR die(mysql_error());
while($row=mysql_fetch_array($query)){
   $friendid=$row['friend'];//here is the id of ur friend.
  /*query the db for his name if he/she is online*/
  $sql=mysq_query("SELECT name,online FROM characters WHERE   guid='$friendid' AND online='1'");
 $count=mysql_num_rows($sql);/*if  greater than 0,means 1...which shows he/she is online*/
 if($count>0){
 $row=mysql_fetch_array($sql);
 $name=$row['name'];

 echo"$name<br/>";
}

}/*close while loop*/

I HOPE THAT HELPS..I DIDN`T TEST THE CODE.

commented: +=+ good answer +1
$sql=mysq_query("SELECT name,online FROM characters WHERE   guid='$friendid' AND online='1'");

I did not know you could use SELECT on more than one field, that is good to know.

Thank you mrcniceguy, I will test the code later today once I have access to the database. Will post results.

So I found out the log in script does not connect to the proper database for this script to work properly as the information I need from _SESSION is not there. I do not wish to alter the log in script at this time, to facilitate this addition.

Thanks for your help mrcniceguy. It's been greatly appreciated.

Waffles

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.