Hello, I have 2 tables: 1.user info: user_id, name, city 2. books info: book_id, user_id, title, category ( every book belong to some user - user_id) what will be the PHP code if I want to print all the DRAMA books from users who lives in NEW_YORK ? Thank you in advance.
You actually need the MYSQL query , if so here it is : $result = mysql_query("SELECT * FROM books as b LEFT JOIN users as u ON b.user_id = u.user_id WHERE u.city = 'NEW_YORK' AND b.category = 'DRAMA'"); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { echo $row['title'].' - '.$row['category'].' - '.$row['name'].' - '.$row['city'].'<br />'; } } PHP:
First of all- Thanks! second - can you please explain to me, part by part, what you did? books as b LEFT JOIN users as u ON b.user_id = u.user_id WHERE u.city = 'NEW_YORK' AND b.category = 'DRAMA' PHP: what is "b" and "u"? does LEFT JOIN do the maching between BOOKS and USRES tables?