Jump to content

Recommended Posts

ok at the moment i have this set up 

 

in my db i have

 

friendname username

 

so i currently use

 <?php $get_username_value = get_username($id);
$query = "SELECT * FROM `friends` WHERE `username` = '$get_username_value'"; ?> 

to get a username out who the perosn is friends with... but then i go the the friendsname profile it displays there name and not the username form "username" ( the person who ask them to be added) how can i combat this?

Link to comment
https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/
Share on other sites

you have a function called get_username?

aside from that, it should be something like this:

<?php
$query = "SELECT * FROM `friends` WHERE `username`='{$get_username_value}';";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$friends = $row['friendname'];
print $friends;
?>

humm this code

 

<?php
$query = "SELECT * FROM `friends` WHERE `username`='{$get_username_value}';";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$friends = $row['friendname'];
print $friends;
?>

  prints the 1st name in my db only but on every profile...

ahh ok yes that works... BUT is there away to work  it the other way around sooo

 

 

friendname        username

  runnerjp          jonsjava

 

 

jonsjava is friends with runnerjp  so on jonsjava profile display runnerjp as a friend

but

runnerjp is also firends with jonsjava so display jonsjava on runnerjps profile

also how would i get this to work properly

 

<?php 
session_start();
require_once '../settings.php';
checkLogin ('1 2');
$query = "SELECT * FROM `friends` WHERE `username`= '$username';";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)){
$friends= $row['friendname'];
}
$sql = "SELECT image FROM users WHERE username = '$friends'";
$result = mysql_db_query($database,$sql,$connection) or die(mysql_error().'<br />Query was:'.$sql);
while($row = mysql_fetch_assoc($result)){
$image     = $row["image"]; 
}
echo $friends;
echo $image;
  ?>

can any 1 yet tell me how i could pull both name or would i have to do something like this

 

|id| username | ... | friends|

| 1|user1 | ... | 2,9,13|

| 2|user2 | ... | 1,8,12|

User 1 would be friends with users 2, 9, and 13. User 2 would be friends with users 1, 8, and 12.

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.