jjackosiris Posted July 13, 2011 Share Posted July 13, 2011 Hi folks, I am trying to get the code to call the product options via the associate id to display the multiple options with the same associate id to be displayed alongside the main product details but I am not sure how to do this correctly... Help would be awesome!... "productdetails" table holds associate id, product name, description and image details - "productoptions" table holds associate id (which there can be multiple "options" in this table with the same associate id but the other option details are different) and option description, option price and option status... $query = "SELECT associate_id, product_id, product_name, product_description, product_image, category_id FROM productdetails WHERE category_id = '0002' ORDER BY category_id, product_id ASC LIMIT $offset, $recordsPerPage;"; $result = mysql_query($query) or die('Error retrieving product listings. Please <a href="contact.php">inform us of this issue</a>.'); $listproducts = '<div id="bagsandclothing">'; while($row = mysql_fetch_assoc($result)) { $associateid = $row[associate_id]; $row[product_name] = stripslashes($row[product_name]); $row[product_description] = stripslashes($row[product_description]); $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p> \n\tTHIS IS WHERE THE OTHER WHILE LOOP NEEDS TO BE PLACED (code below) TO SHOW MULTIPLE OPTIONS FROM ANOTHER TABLE WHICH RECORDS ARE ASSOCIATED WITH - "ASSOCIATE_ID" - \n\t</td> \n\t</tr> \n\t</tr> \n\t</table> \n<p> \n</div>"; } CODE BELOW NEEDS TO BE PLACED IN THE "productdetails" TABLE CELL UNDER THE "$row[product_description]<p>" LINE.... Anyone able to give me some help!?? $associateid = mysql_real_escape_string($associateid); //call product purchase options in the "productoptions" table via product "associate_id" which is in both "productdetails" and "productoptions" tables... $sql = "SELECT associate_id, product, product_option_description, product_option_price, product_option_status FROM productoptions WHERE associate_id = $associateid"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $associate_id = $row["associate_id"]; $product = $row["product"]; $product_option_description = $row["product_option_description"]; $product_option_price = $row["product_option_price"]; $product_option_status = $row["product_option_status"]; if ($product_option_status == "Temporarily Sold Out") { $purchaseproduct = "<a id=\"notinstockmsg\" href=\"#productnotinstockmsg\" class=\"basketnotstock\">Add to Basket</a><p>"; } elseif ($product_option_status == "Coming Soon") { $purchaseproduct = "<a id=\"comingsoonmsg\" href=\"#productcomingsoonmsg\" class=\"basketnotstock\">Add to Basket</a><p>"; } elseif ($product_option_status == "Made To Order") { $purchaseproduct = "<a href=\"basket.php?action=addtobasket&productid=".$product_id."&categoryid=".$categoryid."&cmrbasketid=".$basketid."\" title=\"add ".$row[product]." to basket\" class=\"basketinstock\">Add to Basket</a><p>"; } else { $purchaseproduct = "<a href=\"basket.php?action=addtobasket&productid=".$product_id."&categoryid=".$categoryid."&cmrbasketid=".$basketid."\" title=\"add ".$row[product]." to basket\" class=\"basketinstock\">Add to Basket</a><p>"; } } Thank you for any help you are able to give! TD Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 15, 2011 Author Share Posted July 15, 2011 Since my first post which hasn't had any responses, I have added / changed the code to the following and I am close to the result I am looking for, however there is still a syntax issue which I cannot overcome. Can anyone help me out from the revised code please? $query = "SELECT * FROM productdetails WHERE category_id = '0002' ORDER BY category_id, product_id ASC LIMIT $offset, $recordsPerPage;"; $result = mysql_query($query) or die('Error retrieving product listings. Please <a href="contact.php">inform us of this issue</a>.'); $listproducts = '<div id="bagsandclothing">'; while($row = mysql_fetch_assoc($result)) { $associateid = $row[associate_id]; $product_id = $row[product_id]; $categoryid = $row[category_id]; $row[product_image] = $row[product_image]; $row[product_name] = stripslashes($row[product_name]); $row[product_description] = stripslashes($row[product_description]); $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p> ". $associateid = mysql_real_escape_string($associateid); $sql = "SELECT * FROM productoptions WHERE associate_id = $associateid"; $result2 = mysql_query($sql); while($row2 = mysql_fetch_assoc($result2)) { $popid = $row2["id"]; $associate_id = $row2["associate_id"]; $product = $row2["product"]; $product_option_description = $row2["product_option_description"]; $product_option_price = $row2["product_option_price"]; $product_option_status = $row2["product_option_status"]; if ($product_option_status == "Temporarily Sold Out") { echo "$product_option_description - £$product_option_price - $product_option_status <a id=\"notinstockmsg\" href=\"#productnotinstockmsg\" class=\"basketnotstock\">Add to Basket</a><p>"; } elseif ($product_option_status == "Coming Soon") { echo "$product_option_description - £$product_option_price - $product_option_status <a id=\"comingsoonmsg\" href=\"#productcomingsoonmsg\" class=\"basketnotstock\">Add to Basket</a><p>"; } elseif ($product_option_status == "Made To Order") { echo "$product_option_description - £$product_option_price - $product_option_status <a href=\"basket.php?action=addtobasket&productid=".$product_id."&categoryid=".$categoryid."&cmrbasketid=".$basketid."&popid=".$popid."\" title=\"add ".$row[product]." to basket\" class=\"basketinstock\">Add to Basket</a><p>"; } else { echo "$product_option_description - £$product_option_price - $product_option_status <a href=\"basket.php?action=addtobasket&productid=".$product_id."&categoryid=".$categoryid."&cmrbasketid=".$basketid."&popid=".$popid."\" title=\"add ".$row[product]." to basket\" class=\"basketinstock\">Add to Basket</a><p>"; } } ." \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; } $listproducts .= "\n</div>"; echo $listproducts; ?> Parse error: syntax error, unexpected '.' in bagsandclothing.php on line 219 Many thanks for any help you can provide Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 15, 2011 Share Posted July 15, 2011 Short answer is: DO NOT run query loops inside of query loops. This will create MANY, MANY headaches. Which I'm sure that you are aware of now. Using this single query, you should get all the info that the two queries get. Try it, and let us know of any further problems. "SELECT a.*,b.* FROM productdetails AS a JOIN productoptions AS b ON a.associate_id = b.associate_id WHERE a.category_id = '0002' ORDER BY a.category_id, a.product_id ASC LIMIT $offset, $recordsPerPage;"; Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 16, 2011 Author Share Posted July 16, 2011 Thank you for your reply. I will give this method a go and report back. Many thanks for the advice Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 16, 2011 Author Share Posted July 16, 2011 Short answer is: DO NOT run query loops inside of query loops. This will create MANY, MANY headaches. Which I'm sure that you are aware of now. Using this single query, you should get all the info that the two queries get. Try it, and let us know of any further problems. "SELECT a.*,b.* FROM productdetails AS a JOIN productoptions AS b ON a.associate_id = b.associate_id WHERE a.category_id = '0002' ORDER BY a.category_id, a.product_id ASC LIMIT $offset, $recordsPerPage;"; I have tried what you have suggested but here is the senario: I have two tables. The first is called "productdetails" which holds the following: associate_id product product_description product_image category_id This table holds the products main details, along with an ID - this being the associate_id, which is also in another table which holds the product purchase options such as: Small - £4.99 - In Stock Medium - £6.99 - In Stock Large - £8.99 - Coming Soon This table is called "productoptions". These product options are associated with the product details table with the use of the associate_id. So a record in the product details table can look like so: associate_id 001 product Thermal Jacket product description Comfortable thermal jacket for use in....blabla.... product image thermaljacket.jpg And records in the product options table can look like so: associate_id 001 option description Small option price 4.99 option status In Stock -- associate_id 001 option description Medium option price 6.99 option status In Stock So there can be a number of product options for the same product which are all associated with the same associate_id. Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 16, 2011 Share Posted July 16, 2011 Have you ran the query I gave you in your database management software (phpMyAdmin), or the database console itself? Because, I re-created your tables, with your data, and get the expected results. associate_id product product_description product_image category_id associate_id option_description option_price option_status 1 Thermal Jacket Comfortable jacket.jpg 2 1 small 4.99 in stock 1 Thermal Jacket Comfortable jacket.jpg 2 1 medium 6.99 in stock Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 16, 2011 Author Share Posted July 16, 2011 Have you ran the query I gave you in your database management software (phpMyAdmin), or the database console itself? Because, I re-created your tables, with your data, and get the expected results. associate_id product product_description product_image category_id associate_id option_description option_price option_status 1 Thermal Jacket Comfortable jacket.jpg 2 1 small 4.99 in stock 1 Thermal Jacket Comfortable jacket.jpg 2 1 medium 6.99 in stock I did and I do get the same result as you but I am not sure PHP wise what to do to display what I am after <?php include('_inc/productoverview_config.php'); include('_inc/listproducts_config.php'); if(isset($_GET['p'])) { $pageNum = $_GET['p']; settype($pageNum, 'integer'); } $offset = ($pageNum - 1) * $recordsPerPage; $query = "SELECT a.*,b.* FROM productdetails AS a JOIN productoptions AS b ON a.associate_id = b.associate_id WHERE a.category_id = '0002' ORDER BY a.category_id, a.product_id ASC LIMIT $offset, $recordsPerPage;"; $result = mysql_query($query) or die('Error retrieving product listings. Please <a href="contact.php">inform us of this issue</a>.'); $listproducts = '<div id="bagsandclothing">'; while($row = mysql_fetch_assoc($result)) { $associateid = $row[associate_id]; $product_id = $row[product_id]; $categoryid = $row[category_id]; $row[product_image] = $row[product_image]; $row[product_name] = stripslashes($row[product_name]); $row[product_description] = stripslashes($row[product_description]); $popid = $row["id"]; $associate_id = $row["associate_id"]; $product = $row["product"]; $product_option_description = $row["product_option_description"]; $product_option_price = $row["product_option_price"]; $product_option_status = $row["product_option_status"]; $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p>THIS IS WHERE THE MULTIPLE "PRODUCT OPTIONS" HAVE TO BE DISPLAYED... Not sure what to put here?? \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; } $listproducts .= "\n</div>"; echo $listproducts; ?> Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 16, 2011 Share Posted July 16, 2011 Ah, OK, mis-understood you. I'm going to attempt to get the while loop right. Crude Attempt while($row = mysql_fetch_assoc($result)) { $options = $row['option_description'] . ' ' . $row['option_price'] . ' ' . $row['option_status'] . '<br />'; if($last != $row['associate_id']) { $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p>"; } $listproducts .= $options; if($last != $row['associate_id']) { $listproducts .= " \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; $last = $row['associate_id']; } } Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 16, 2011 Author Share Posted July 16, 2011 Ah, OK, mis-understood you. I'm going to attempt to get the while loop right. Crude Attempt while($row = mysql_fetch_assoc($result)) { $options = $row['option_description'] . ' ' . $row['option_price'] . ' ' . $row['option_status'] . '<br />'; if($last != $row['associate_id']) { $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p>"; } $listproducts .= $options; if($last != $row['associate_id']) { $listproducts .= " \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; $last = $row['associate_id']; } } jcbones, you are brilliant, it has displayed all the options from the associate id!! Thank you so much! There are a couple of things though I would like bring up... One of the options is displayed within the table, yet (where applicable) the other options for that associate id are outwith the table as you can see in the image I have attached. Also, how would I add the following to what you have written? if ($product_option_status == "Temporarily Sold Out") { echo "$product_option_description - £$product_option_price - $product_option_status <a id=\"notinstockmsg\" href=\"#productnotinstockmsg\" class=\"basketnotstock\">Add to Basket</a><p>"; } elseif ($product_option_status == "Coming Soon") { echo "$product_option_description - £$product_option_price - $product_option_status <a id=\"comingsoonmsg\" href=\"#productcomingsoonmsg\" class=\"basketnotstock\">Add to Basket</a><p>"; } elseif ($product_option_status == "Made To Order") { echo "$product_option_description - £$product_option_price - $product_option_status <a href=\"basket.php?action=addtobasket&productid=".$product_id."&categoryid=".$categoryid."&cmrbasketid=".$basketid."&popid=".$popid."\" title=\"add ".$row[product]." to basket\" class=\"basketinstock\">Add to Basket</a><p>"; } else { echo "$product_option_description - £$product_option_price - $product_option_status <a href=\"basket.php?action=addtobasket&productid=".$product_id."&categoryid=".$categoryid."&cmrbasketid=".$basketid."&popid=".$popid."\" title=\"add ".$row[product]." to basket\" class=\"basketinstock\">Add to Basket</a><p>"; } The updated code you provided along with what I had already: <?php include('_inc/productoverview_config.php'); include('_inc/listproducts_config.php'); if(isset($_GET['p'])) { $pageNum = $_GET['p']; settype($pageNum, 'integer'); } $offset = ($pageNum - 1) * $recordsPerPage; $query = "SELECT a.*,b.* FROM productdetails AS a JOIN productoptions AS b ON a.associate_id = b.associate_id WHERE a.category_id = '0002' ORDER BY a.category_id, a.product_id ASC LIMIT $offset, $recordsPerPage;"; $result = mysql_query($query) or die('Error retrieving product listings. Please <a href="contact.php">inform us of this issue</a>.'); $listproducts = '<div id="bagsandclothing">'; while($row = mysql_fetch_assoc($result)) { $associateid = $row[associate_id]; $product_id = $row[product_id]; $categoryid = $row[category_id]; $row[product_image] = $row[product_image]; $row[product_name] = stripslashes($row[product_name]); $row[product_description] = stripslashes($row[product_description]); $popid = $row["id"]; $associate_id = $row["associate_id"]; $product = $row["product"]; $product_option_description = $row["product_option_description"]; $product_option_price = $row["product_option_price"]; $product_option_status = $row["product_option_status"]; $options = $row['product_option_description'] . ' £' . $row['product_option_price'] . ' ' . $row['product_option_status'] . '<br />'; if($last != $row['associate_id']) { $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p>"; } $listproducts .= $options; if($last != $row['associate_id']) { $listproducts .= " \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; $last = $row['associate_id']; } } $listproducts .= "\n</div>"; echo $listproducts; ?> Cannot thank you enough for the help you have provided! Really! It has been driving me mad and I have learnt a great deal from what you have written! [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 16, 2011 Author Share Posted July 16, 2011 I've managed to do the if, elseif, else with the $options if ($product_option_status == "Temporarily Sold Out") { $options = $row['product_option_description'] . ' - £' . $row['product_option_price'] . ' - ' . $row['product_option_status'] . ' <a id="notinstockmsg" href="#productnotinstockmsg" class="basketnotstock">Add to Basket</a><p>'; } elseif ($product_option_status == "Coming Soon") { $options = $row['product_option_description'] . ' - £' . $row['product_option_price'] . ' - ' . $row['product_option_status'] . ' <a id="comingsoonmsg" href="#productcomingsoonmsg" class="basketnotstock">Add to Basket</a><p>'; } elseif ($product_option_status == "Made To Order") { $options = $row['product_option_description'] . ' - £' . $row['product_option_price'] . ' - ' . $row['product_option_status'] . ' <a href="basket.php?action=addtobasket&productid='.$product_id.'&categoryid='.$categoryid.'&cmrbasketid='.$basketid.'&popid='.$popid.'" title="add '.$row[product].' to basket" class="basketinstock">Add to Basket</a><p>'; } else { $options = $row['product_option_description'] . ' - £' . $row['product_option_price'] . ' - ' . $row['product_option_status'] . ' <a href="basket.php?action=addtobasket&productid='.$product_id.'&categoryid='.$categoryid.'&cmrbasketid='.$basketid.'&popid='.$popid.'" title="add '.$row[product].' to basket" class="basketinstock">Add to Basket</a><p>'; } I just need help getting the other options within the table - as they are outside as in the image I attached above... Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 16, 2011 Share Posted July 16, 2011 Try it again with this: doesn't include your last post <?php include('_inc/productoverview_config.php'); include('_inc/listproducts_config.php'); if(isset($_GET['p'])) { $pageNum = $_GET['p']; settype($pageNum, 'integer'); } $offset = ($pageNum - 1) * $recordsPerPage; $query = "SELECT a.*,b.* FROM productdetails AS a JOIN productoptions AS b ON a.associate_id = b.associate_id WHERE a.category_id = '0002' ORDER BY a.category_id, a.product_id ASC LIMIT $offset, $recordsPerPage;"; $result = mysql_query($query) or die('Error retrieving product listings. Please <a href="contact.php">inform us of this issue</a>.'); $listproducts = '<div id="bagsandclothing">'; $last = NULL; while($row = mysql_fetch_assoc($result)) { $associateid = $row['associate_id']; $product_id = $row['product_id']; $categoryid = $row['category_id']; $row['product_image'] = $row['product_image']; $row['product_name'] = stripslashes($row['product_name']); $row['product_description'] = stripslashes($row['product_description']); $popid = $row["id"]; $associate_id = $row["associate_id"]; $product = $row["product"]; $product_option_description = $row["product_option_description"]; $product_option_price = $row["product_option_price"]; $product_option_status = $row["product_option_status"]; if($last != $row['associate_id']) { if(!empty($options)) { $listproducts = str_replace('{{OPTIONS}}',implode('<br /> ',$options),$listproducts); } $options = array(); $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p>{{OPTIONS}} \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; $last = $row['associate_id']; } $options[] = $row['product_option_description'] . ' £' . $row['product_option_price'] . ' ' . $row['product_option_status']; } $listproducts .= "\n</div>"; echo $listproducts; ?> Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 17, 2011 Author Share Posted July 17, 2011 Try it again with this: doesn't include your last post <?php include('_inc/productoverview_config.php'); include('_inc/listproducts_config.php'); if(isset($_GET['p'])) { $pageNum = $_GET['p']; settype($pageNum, 'integer'); } $offset = ($pageNum - 1) * $recordsPerPage; $query = "SELECT a.*,b.* FROM productdetails AS a JOIN productoptions AS b ON a.associate_id = b.associate_id WHERE a.category_id = '0002' ORDER BY a.category_id, a.product_id ASC LIMIT $offset, $recordsPerPage;"; $result = mysql_query($query) or die('Error retrieving product listings. Please <a href="contact.php">inform us of this issue</a>.'); $listproducts = '<div id="bagsandclothing">'; $last = NULL; while($row = mysql_fetch_assoc($result)) { $associateid = $row['associate_id']; $product_id = $row['product_id']; $categoryid = $row['category_id']; $row['product_image'] = $row['product_image']; $row['product_name'] = stripslashes($row['product_name']); $row['product_description'] = stripslashes($row['product_description']); $popid = $row["id"]; $associate_id = $row["associate_id"]; $product = $row["product"]; $product_option_description = $row["product_option_description"]; $product_option_price = $row["product_option_price"]; $product_option_status = $row["product_option_status"]; if($last != $row['associate_id']) { if(!empty($options)) { $listproducts = str_replace('{{OPTIONS}}',implode('<br /> ',$options),$listproducts); } $options = array(); $listproducts .= "\n \n<div id=\"productview\"> \n\t<table class=\"productname\"> \n\t<tr valign=\"middle\"> \n\t<td class=\"productname\"> \n\t$row[product_name] \n\t</td> \n\t</tr> \n\t</table> \n\t<table class=\"productoverview\"> \n\t<tr valign=\"top\"> \n\t<td class=\"productpicture\"> \n\t<img src=\"_productimages/_thumbs/$row[product_image]\" title=\"$row[product_name]\" border=\"0\" /> \n\t<p> \n\t<span class=\"enlargephoto\"><a id=\"showlargepic\" href=\"_productimages/$row[product_image]\" class=\"enlarge\">Enlarge Photograph</a></span> \n\t</td> \n\t<td class=\"productdetails\"> \n\t$row[product_description] \n\t<p>{{OPTIONS}} \n\t</td> \n\t</tr> \n\t</table> \n<p> \n</div>"; $last = $row['associate_id']; } $options[] = $row['product_option_description'] . ' £' . $row['product_option_price'] . ' ' . $row['product_option_status']; } $listproducts .= "\n</div>"; echo $listproducts; ?> Thanks for your reply and taking your time in helping. Yes this did sort out the other options and are now in the table beneath the first option! Only thing is now is that the last record in the page, no option is displayed, only {{OPTIONS}} ? Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 17, 2011 Share Posted July 17, 2011 Replace: echo $listproducts; with: echo str_replace('{{OPTIONS}}',implode('<br /> ',$options),$listproducts); Should have caught that on the first go around. Quote Link to comment Share on other sites More sharing options...
jjackosiris Posted July 17, 2011 Author Share Posted July 17, 2011 Replace: echo $listproducts; with: echo str_replace('{{OPTIONS}}',implode('<br /> ',$options),$listproducts); Should have caught that on the first go around. jcbones - thank you so much for the code and all your help you have provided me! that done the job!! Thanks alot! 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.