Jump to content

Get name by ID from other table


badeand

Recommended Posts

This is a part of my Mysql query and getting the values from the rows wheres tasks.owner.id = logged in user so it only shows the tasks assigned to the logged in user.

 

This is a task manager script i?m trying to make, so i want it to echo out who made this task by name, and the ID of the user that made it is stored in $made_id in table "tasks" and i need this to get the name (row) with the same id in the "users" table.

 

How could i do this?

 

As i see it, the query already contains booth the ID and the Name of the users, but i need to put theese to together in some way.

 

$query = mysql_query("SELECT * FROM tasks JOIN login_users WHERE tasks.owner_id = '$user' GROUP BY tasks.id ");

if ( mysql_num_rows( $query ) > 0 )
{

while ($row = mysql_fetch_array($query)){

$id = $row['id'];
$title = $row['title'];
$details = $row['details'];
$yourref = $row['yourref'];
$made_id = $row['made_id'];
$made_date = $row['made_date'];
$due_date = $row['due_date'];
$name = $row['name'];


?>

Link to comment
Share on other sites

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/home.php on line 36

 

$query = mysql_query("SELECT *, b.name FROM tasks AS a LEFT JOIN login_users AS b ON a.owner_id=b.id WHERE a.owner_id = '$user' GROUP BY a.id");

 

 

The table names are correct.

 

Should it be:

 

ON a.made_id=b.id

 

Since it`s the made_id that i?m trying to link up with the id on the users table?

 

But this query failed as well..

Link to comment
Share on other sites

Ok, so now it?s finaly returning results, and correct results.

 

Solved ;)

 

$query = mysql_query("SELECT *, b.name FROM tasks AS a LEFT JOIN login_users AS b ON a.made_id=b.user_id WHERE a.owner_id = '$user'");

 

Works fine!

 

Thanks for the help

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.