Jump to content

[SOLVED] for loop problem, I think this is a simple fix one! (I hope)


emma57573

Recommended Posts

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>';
	}

 

 

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>';

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.