Jump to content

a nested loop problem


lauralee

Recommended Posts

Well, well, well here it is:$prods = @mysql_query('SELECT * FROM products INNER JOIN family1 ON family1.familyid = products.family_id WHERE familyid="' . $row['familyid'] . '" ORDER BY products.id');The problem was that I needed the double quotes before the single quote and after the single quote because of the . variable $row['familyid']Thanks for all of the suggestions. I suddenly saw it after thescientist mentioned the variable aspect. The double quotes weren't needed, but because it would normally be written familyid = " ", I needed to add familyid="' . $row['familyid'] . '" the variable inside the double quotes for a string.Thanks, again for helping me work through this!I'm now working on another related, very similar nested loop problem. I'll be back if I can't figure it out on my own.
you may not need to quote around if 'familyid" is integer data type. if its string then you must quote it. you can also quote the column data in the double quots as thescinitsi was sugested
("SELECT col1,col2 FROM products INNER JOIN family1 ON family1.familyid = products.family_id WHERE familyid='{$row['familyid']}' ORDER BY id");

look for the single quote and the curly braces (interpolation) around $row['familyid']

Link to comment
Share on other sites

for more information how php react in different quoteshttp://www.php.net/manual/en/language.types.string.php..you will find more info related to the interpolation also here.

Link to comment
Share on other sites

for more information how php react in different quoteshttp://www.php.net/manual/en/language.types.string.php..you will find more info related to the interpolation also here.
Thanks. I've checked out the manual while learning PHP, but sometimes it is difficult to understand because I don't have enough knowledge of the subject to be able to use what it says.
Link to comment
Share on other sites

Thanks. I've checked out the manual while learning PHP, but sometimes it is difficult to understand because I don't have enough knowledge of the subject to be able to use what it says.
you can post here where you are facing problem to get. all will try to help you to get that.
Link to comment
Share on other sites

you can post here where you are facing problem to get. all will try to help you to get that.
That is exactly what I do when I hit a problem that I can't solve. I use the forum and have always had great results. Thanks to all of you experts for being there and giving of your time to help.
Link to comment
Share on other sites

Well, here is another nested loop problem on the same code that I've been working on. Now I want to show those products of the same size with different colors only once with the submit buttons for each color listed below the product description. Can I use another INNER JOIN with another while loop that will show only one size with the available colors listed below the product?Or should I try using an If statement to filter the size then the colors?The entire code I have now is below - but it still lists each product without showing a color submit button below each product. I'm not sure how to filter the sizes so that the product description shows only once for each size, then lists the color submit buttons below. Suggestions?$result = @mysql_query('SELECT * FROM family1 WHERE inactive=" "');if (!$result) {exit('<p>Error performing query: ' .mysql_error() . '</p>');}while ($row = mysql_fetch_array($result)){echo '<div class="product-b-1">';echo'<p><img class="products" src="/images/products/' . $row['family_name'] . '.jpg" alt="' . $row['family_name'] . '"></img><span>' . $row['family_name'] . '</span></p>';echo ' <p>' . bbcodeout($row['familydescription']) . '</p>';echo '</div>';$prods = @mysql_query('SELECT * FROM products INNER JOIN family1 ON family1.familyid = products.family_id WHERE familyid="' . $row['familyid'] . '" ORDER BY products.id');if (!$prods) {exit('<p>Error performing query: ' .mysql_error() . '</p>');}while ($typ = mysql_fetch_array($prods)){echo '<div class="product-b-1">';echo '<div class="pricebox">' . '$ ' . $typ['list_price'] . '</div><div class="productboxcolor">' . $typ['size'] . '</div>';echo '<div class="buttonbox"><form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">';echo '<input type="hidden" name="cmd" value="_s-xclick">';echo '<input type="hidden" name="hosted_button_id" value="' . $typ['button'] . '">';echo '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form></div>';echo'<p><img class="products" src="/images/products/' . $typ['id'] . '.jpg" alt="' . $typ['id'] . '"></img><span>' . $typ['id'] . '</span></p>';echo ' <p>' . bbcodeout($typ['description']) . '<br /></p>';echo '</div>';}$prod_color = @mysql_query('SELECT color FROM products INNER JOIN colors ON colors.color_name=products.color WHERE color_name = "' . $typ['color'] . '" ORDER BY colors.color_name');if (!$prod_color) {exit('<p>Error performing color query: ' .mysql_error() . '</p>');}while ($clr = mysql_fetch_array($prod_color)){echo '<form>';echo '<div class="buybox">';echo '<input type="radio" name="' . $clr['color'] . '" value="' . $clr['color'] . '" id="' . $clr['color'] . '" /> <label>' . $clr['color'] . '</label><br />';echo '<div class="buttonbox">Buy</div></div>';echo '</form>';echo '</div>';echo '</div>';}}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...