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
https://forums.phpfreaks.com/topic/266332-get-name-by-id-from-other-table/
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..

Archived

This topic is now archived and is closed to further replies.

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