Jump to content

mysql query within while loop of another query


yandoo

Recommended Posts

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.