My case is this: I have three tables: user, search_queries, and comments.
I want to display variable that I am getting from these three queries.
I have used INNER JOIN for both user and search_queries. This works very fine.
But how do I get the variables from the third table?
Below is my code so far.
<?php
$sql24 = "SELECT * FROM comments WHERE search_id=$search_id";
$result24=mysql_query($sql24);
$sql = "SELECT * FROM user INNER JOIN search_queries ON user.id = search_queries.id
ORDER BY search_id DESC";
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result))
{
$fname =$row['fname'];
$sname=$row['sname'];
$id=$row['id'];
$email=$row['email'];
$profile_pic=$row['profile_pic'];
$city=$row['city'];
$country=$row['country'];
$search_date=$row['search_date'];
$QUERY=$row['QUERY'];
$search_id=$row['QUERY'];
//-display the result of the array
echo "the results from 2nd query ";
echo "the results from the 3rd query ";
}
?>
Fields in the underlying tables:
- user: id, email, fname, sname, pass, city, profile_pic, etc.
- comments: com_id, id, comment, date, etc.
- search_queries: search_id, id, QUERY, date etc.
Instead, the first select query doesnt seem to work.
Please help.