problem with Passing multiple values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tolearn
Forum Newbie
Posts: 9
Joined: Wed Nov 29, 2006 5:27 am

problem with Passing multiple values

Post 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]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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 ?
Post Reply