I need to create a report which contains user input. I have 2 tables:
a table containing a specific group of users
a table containing user suggestions [/list=1]
This second table contains suggestions from a larger group. In my report I just want a list of table2 suggestions from the specific users in table 1.
Can I do this in one SELECT statement or do I need to have nested while loops something like this:
$sql1 = "SELECT * FROM table1 ORDER BY user"; $result1 = mysql_query($sql1,$dblink); while ($row1 = mysql_fetch_array($result1)) { $sql2 = "SELECT * FROM table2 WHERE user = '".$row1['user']."'"; $result2 = mysql_query($sql2,$dblink); while ($row2 = mysql_fetch_array($result2)) { //build report here } }
Try this -
$sql1 = "SELECT * FROM table1, table2 WHERE table1.user=table2.user ORDER BY table1.user";
Hope this helps 😉