yandoo Posted July 8, 2013 Share Posted July 8, 2013 Hiya I'm trying to create a query that selects items from a table based on the id from another table. A tip is called from the tips table and then in the while loop as each row is processed the comments associated for that tip should be outputted as well. $sql = mysql_query("SELECT * FROM tips ORDER BY date_added DESC $limit"); $productCount = mysql_num_rows($sql); // count the output amount} if ($productCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $details = $row["details"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $share = $row["share"]; $meta = $row["meta"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $sql5 = mysql_query("SELECT * FROM comment WHERE id = '$id' ORDER BY date DESC") or die(mysql_error()); echo $id; echo'<br/>'; echo $product_name; echo'<br/>'; echo $details; echo'<br/>'; echo $comment; echo'<br/>'; This has given an undefined index error so I tried to make sure everything was set using if (isset($_GET['comment])) { // safe to use } Which didn't change anything, perhaps I'm missing something major? How do I achieve this please? Thank you kindly. Quote Link to comment Share on other sites More sharing options...
Solution yandoo Posted July 8, 2013 Author Solution Share Posted July 8, 2013 If I add another while loop for the second query: while($row = mysql_fetch_array($sql5)){ Am I correct in thinking that with each row processed from the first query, all rows will be processed from the second where the id is same? Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.