Question:

Can you help me with a MySQL Query?

by  |  earlier

0 LIKES UnLike

I have a database with a many-to-many relationship.

Table_People:

ID

Name

Table_Class:

ID

Time

Table_Link:

People_ID

Class_ID

I want to select all People_ID's from Table_Link where Class_ID = the user input but I also want to display the Name from Table_People. How do I do this?

I have:

$result = mysql_query("SELECT People_ID FROM Table_Link WHERE Class_ID='{$userInput}'");

This gives me the ID's of the people but not their name.

 Tags:

   Report

2 ANSWERS


  1. Link the tables people_ID with ID, and then query for table_people.  


  2. $query = "SELECT * FROM Table_People tp, Table_Link tl WHERE tp.ID = tl.People_ID AND tl.Class_ID = $user_input";

    $result = mysql_query($query);

    :)

    * = all columns, I find it easier to just select all most of the time.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.