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

 

 

Link to comment
Share on other sites

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

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.