Jump to content

[SOLVED] For loop in a while loop


graham23s

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.