Page 1 of 1

problem with Passing multiple values

Posted: Wed Dec 13, 2006 5:11 am
by tolearn
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

i have a list of items created dynamically  each with an order id,product id got from database and in hidden field and batch id which has to be selected from a dropdown menu.

Code: Select all

<input type="hidden" name="order_ID" value="<?php echo $order_ID; ?>">
<input type="hidden" name="product_ID" value="<?php echo $product_ID; ?>">
				<select name="batch_list[<?php echo $i; ?>]"><option value="">Select</option>                   
				<?php 
				$result2 = mysql_query("SELECT * FROM tbl_batch");
				while($row2 = mysql_fetch_array($result2))
 				     {
				?>
                <option  value="<?php echo $row2[0]; ?>"><?php echo $row2[0]; ?></option>
					 <?php
					 }
					 $i++;
					 }
			         mysql_close($con);
			         ?>
                </select>
I have to pass this value to the next page and insert into a table

Im getting the batch id correctly but i get the order id and product id of last item only.

How to get the correct values?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Dec 13, 2006 5:30 am
by CoderGoblin
Please the the PHP/Code tags when dealing with code. It makes our lives easier...
I think the reason you are only getting the last orderid and product id is you only have 1, You need to make them arrays... Also ensure the </select> is the right place (probably before the $i++;

Code: Select all

<input type="hidden" name="order_ID[<?php echo $i; ?>]" value="<?php echo $order_ID; ?>">
<input type="hidden" name="product_ID[<?php echo $i; ?>]" value="<?php echo $product_ID; ?>">
Also if you are getting the same "SELECT * FROM tbl_batch" for each $i, why not get it once, store in a variable and simply use the variable ?