There are two user and info tables. The user table contains the user id and its city, and the info table also contains the user id, city, and two more fields, tell me how to display the whole info from the info table for his city?
1 answer
Task : There is a user table user ( user_id user user_id , city ) and help message table ( user_id user user_id , title title , message message ). At the entrance to the city $city . At the exit - a list of messages from users from the same city.
SELECT title, message FROM help h, user u WHERE h.user_id = u.user_id and city = '$city' The final code, jointly debugged in the comments
<?php $db = mysql_connect ("localhost","login","password"); mysql_select_db("dbname",$db); mysql_query("SET NAMES utf8"); $result = mysql_query("SELECT h.title, h.message FROM cms_sos h, cms_user_profiles u WHERE h.user_id = u.user_id AND u.city = '" . $inUser->city . "' LIMIT 10",$db); while($myrow = mysql_fetch_assoc($result)) echo '<p><b>' . $myrow['title']. '</b><br>' . $myrow['message']. '</p>'; mysql_close($db); ?> - Comments are not intended for extended discussion; conversation moved to chat . - Nicolas Chabanovsky ♦
- @NicolasChabanovsky I see. Thank. - Gleb Kemarsky
- @Alexander Pshenichny Added the final code in response. If everything is ok, click on the check mark on the side of the answer that it is accepted. Tour - Gleb Kemarsky
|
JOIN- Invisioninfo, each user has only the same city or there users have several cities and they need to select information only on their home city? Can you add field names in the tables? - Gleb Kemarsky