Reputation: 522
I have 2 tables : movies, schedule .
Schedule : schedule_id, movie_id, start_date, start_time ;
Movies: movie_id, movie_name, movie_description ;
I'm using php , and I want to retrieve every record in schedule where start_date = 2014-11-14
which is quite simple but in the same query I want to get movie_name
for every movie_id
in schedule .
And if it's possible how will I access the result?
I used this before: while($row = $rs->fetch_row())
but since I want data from 2 tables how will I access it?
Upvotes: 0
Views: 56
Reputation: 2916
The query you want is this:
SELECT *
FROM Schedule
INNER Movies ON Movies.movie_id = Schedule.movie_id
WHERE Schedule.start_date = '2014-11-14';
You can access it using the same function that you were using
Upvotes: 1
Reputation: 3097
Something along the lines of:
$sql = "SELECT schedule.*, movies.movie_name FROM schedule JOIN movies ON schedule.movie_id = movies.movie_id WHERE schedule.start_data = '2014-11-14'";
You can leave the rest of your code like it is and $row will be ammended with the movie_name
Try researching MySQL JOIN on google ;)
Upvotes: 1