Jump to content

Recommended Posts

I was working on a php based application where a user has followers and follows(Similar to twitter)

I need help in running a query.

$profileuserid has the the userid of the current profile.

 

Table follow has following fields : followerid & followid

 

Table users has following fields: userid & username

 

I need to run a php mysql query that retrieves the usernames from the user tables with the logic below:

I need help with the syntax and execution

 

1. "SELECT followerid FROM follow WHERE followid='$profileuserid'";

2. Select  username from userstable where userid="followid";

 

 

i.e.I need to display all the associated usernames.

 

How do I go about it and display it all at once?

Link to comment
https://forums.phpfreaks.com/topic/238599-mysql-query-to-compare-display/
Share on other sites

include 'db.config.php';

$sql = "SELECT u.username FROM follow AS f JOIN users AS u ON f.follower = u.userid WHERE f.followid = '$profileuserid'";
$result = mysql_query($sql) or trigger_error($sql . ' has an error.<br />' . mysql_error());
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_row($result)) {
echo $row[0] . '<br />';
}
}
else {
echo 'No followers';
}

 

UN-Tested.

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.