graham23s Posted January 11, 2009 Share Posted January 11, 2009 Hi Guys, in my shopping cart i have used the <select> tag so the user can select how many products to add, if the user has 10 items in the cart i was using a for loop to check against to the "selected" tag would be used properly, but the scrip freezes (i know it's because of the for loop in the while lopp to many loops lol) is there an easier way to do this at all? <?php // START GETTING THE CART CONTENTS while ($aC = mysql_fetch_array($rC)) { // CART VARS $cartProdID = $aC['product_id']; $cartProdQY = $aC['quantity']; // WE NEED THE PRODUCTS DETAILS ASWELL $qPD = "SELECT * FROM `fcp_products` WHERE `id`='$cartProdID'"; $rPD = mysql_query($qPD) or diue (mysql_error()); $aPD = mysql_fetch_array($rPD) or die (mysql_error()); // VARS $prodNM = $aPD['product_name']; $prodTH = $aPD['product_thumbnail']; $prodPR = $aPD['product_price']; ?> <td class="CartThumb" style=""> <a href='http://shoppingcart.interspire-demo.com/demo_19105676/products/8-GB-iPod-Nano-%28Green%29.html' ><img src='products/thumbnails/<?php print "$prodTH"; ?>' alt='<?php print "$prodNM"; ?>' border='0'/></a> </td> <td class="ProductName" colspan="1"> <a href="product.php?id=<?php print "$cartProdID"; ?>"><?php print "$prodNM"; ?></a> <br /> </td> <td align="center"> <select onchange="Cart.UpdateQuantity(this.options[this.selectedIndex].value);" id="qty_0" name="qty[0]" class="Field45"> <?php for ($i = 1; $i <= 50; $i++) { print "<option value='$i' "; if ($i = $cartProdQY) { print "selected"; } print ">$i</option>"; } ?> <!--<option value='0'>0</option> <option selected="selected" value="1">1</option> <option value="2">2</option>--> </select> <br /><a href="cart.php?action=remove&product-id=<?php print "$cartProdID"; ?>&customer-id=<?php print "$cusSessionID"; ?>" onclick="Cart.RemoveItem('0'); return false;" class="CartRemoveLink">Delete</a> </td> <td align="center">£<?php print "$prodPR"; ?></td> <td align="right"><em class="ProductPrice">£<?php print "$prodPR"; ?></em></td> </tr> <?php // LOOP ENDS } ?> <tr class="SubTotal"> <td colspan="4">Items:</td> <td><em class="ProductPrice">$199.00</em></td> </tr> <tr style="display:none" class="SubTotal"> <td colspan="4">Shipping ():</td> <td><em class="ProductPrice"></em></td> </tr> <tr style="display: none" class="SubTotal"> <td colspan="4">Handling:</td> <td><em class="ProductPrice"></em></td> </tr> <tr class="SubTotal"> <td colspan="4">Subtotal:</td> <td><em class="ProductPrice">$199.00</em></td> </tr> <tr class="SubTotal" style="display: none"> <td colspan="4">Adjusted Sub Total:</td> <td><em class="ProductPrice">199</em></td> </tr> </tbody> </table> <!-- Bottom button not looped --> <div class="FloatLeft" style="display: "> <input type="image" src="http://shoppingcart.interspire-demo.com/demo_19105676/templates/default/images/blue/UpdateQtyButton.gif" alt="Update" /> </div> </form> <?php } ?> thanks for any help guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/ Share on other sites More sharing options...
RussellReal Posted January 11, 2009 Share Posted January 11, 2009 50 loops is not a problem php does that in a matter of miliseconds $rPD = mysql_query($qPD) or diue (mysql_error()); is probably your problem Quote Link to comment https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/#findComment-734654 Share on other sites More sharing options...
graham23s Posted January 11, 2009 Author Share Posted January 11, 2009 Hi Mate, I didn't even notice that, thanks lol i have narrowed down the problem: if ($i = $cartProdQY) { print "selected"; } this part makes the script freak out and freeze! it prints the quantity like: 4 4 4 4 etc i can't see what the problem is? thanks mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/#findComment-734671 Share on other sites More sharing options...
.josh Posted January 11, 2009 Share Posted January 11, 2009 probably because you are using an assignment operator instead of an equality operator. Quote Link to comment https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/#findComment-734676 Share on other sites More sharing options...
DeanWhitehouse Posted January 11, 2009 Share Posted January 11, 2009 if ($i = $cartProdQY) should be if ($i == $cartProdQY) Quote Link to comment https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/#findComment-734678 Share on other sites More sharing options...
graham23s Posted January 11, 2009 Author Share Posted January 11, 2009 darn thanks guys i better wake up some more lol Graham Quote Link to comment https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/#findComment-734746 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.