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. Link to comment https://forums.phpfreaks.com/topic/279957-mysql-query-within-while-loop-of-another-query/ Share on other sites More sharing options...
yandoo Posted July 8, 2013 Author 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 Link to comment https://forums.phpfreaks.com/topic/279957-mysql-query-within-while-loop-of-another-query/#findComment-1439875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.