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
https://forums.phpfreaks.com/topic/140384-solved-for-loop-in-a-while-loop/
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

Archived

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

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