emma57573 Posted June 29, 2008 Share Posted June 29, 2008 Im sorry I feel terrible keep coming in here for help! Im stuck on this page http://www.misi.me.uk/cart/cart.php?action=add&id=147 Ive got the basics of the shopping cart working now but Im having trouble with the quantity. Its called from a database and what basically im tring to do is match the product id to the quantity and then add a drop down option for the quantity What I really want is this code: <select name="qty"> <? for($i=1; $i<=$rst["qty"];$i++) { ?> <option value="<? echo $i; ?>"><? echo $i; ?></option> <? } ?> </select> But Im want to insert it in here, which is where im getting confused! is it even allowed in the extract code?: extract($rst); $output[] = '<table width="90%" class="onepxtable" align="center"">'; $output[] = '<tr>'; $output[] = '<td><h2><a href="store_info.php?id='.$rst["uid"].'">'.$rs_t["username"].' Store</a></h2></td>'; $output[] = '</tr>'; $output[] = '<tr>'; $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'"><img src="http://www.misi.me.uk/uploadedimages/'.$freetplq_img["url"].'" width="75" height="75" border="0" class="onepxtable"></a></td>'; $output[] = '<td align="left"><a href="cart.php?action=delete&id='.$id.'" class="smlgrey">Remove<img src="http://www.misi.me.uk/images/delete.gif" border="0" align="left"></a></td>'; $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'">'.$product_name.'</td>'; $output[] = '<td align="left">£'.$buy_price.'</td>'; ///// This is the line that I need it in, ive tried lots of variations to get the loop to work but i just keep getting errors/////////////// $output[] = '<td align="left"><select name="qty">1<option value="'.$qty.'">'.$qty.'</option></select></td></tr>'; ///// This is the line that I need it in://///////////// $output[] = '<tr><td colspan="5" align="right"><class="smlgrey">Sub total</class> £'.($buy_price * $qty).'</td></tr>'; $total += $buy_price * $qty; $output[] = '</tr>'; $output[] = '</table><br><br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/112387-solved-for-loop-problem-i-think-this-is-a-simple-fix-one-i-hope/ Share on other sites More sharing options...
hitman6003 Posted June 29, 2008 Share Posted June 29, 2008 Put the loop outside of inserting it into the array for output. extract($rst); $output[] = '<table width="90%" class="onepxtable" align="center"">'; $output[] = '<tr>'; $output[] = '<td><h2><a href="store_info.php?id='.$rst["uid"].'">'.$rs_t["username"].' Store</a></h2></td>'; $output[] = '</tr>'; $output[] = '<tr>'; $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'"><img src="http://www.misi.me.uk/uploadedimages/'.$freetplq_img["url"].'" width="75" height="75" border="0" class="onepxtable"></a></td>'; $output[] = '<td align="left"><a href="cart.php?action=delete&id='.$id.'" class="smlgrey">Remove<img src="http://www.misi.me.uk/images/delete.gif" border="0" align="left"></a></td>'; $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'">'.$product_name.'</td>'; $output[] = '<td align="left">£'.$buy_price.'</td>'; $select_options = ''; for ($i = 1; $i < $qty; $i++) { $select_options .= '<option value="'.$i.'" ' . ($i == $qty ? 'selected="selected" : '') . '>'.$i.'</option>'; } $output[] = '<td align="left"><select name="qty">' . $select_options . '</select></td></tr>'; $output[] = '<tr><td colspan="5" align="right"><class="smlgrey">Sub total</class> £'.($buy_price * $qty).'</td></tr>'; $total += $buy_price * $qty; $output[] = '</tr>'; $output[] = '</table><br><br>'; Quote Link to comment https://forums.phpfreaks.com/topic/112387-solved-for-loop-problem-i-think-this-is-a-simple-fix-one-i-hope/#findComment-577027 Share on other sites More sharing options...
emma57573 Posted June 30, 2008 Author Share Posted June 30, 2008 Thank you that was very helpful, after much fidderling, ive finally got it working Quote Link to comment https://forums.phpfreaks.com/topic/112387-solved-for-loop-problem-i-think-this-is-a-simple-fix-one-i-hope/#findComment-578010 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.