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
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 3:11 am
I have the following code:
Code: Select all
foreach($_POST['order'] as $orderID=>$orderValue)
{
$amount = current($_POST['amount']);
next($_POST['amount']);
$buy_price = current($_POST['buy_price']);
next($_POST['buy_price']);
$supplier = current($_POST['supplier']);
next($_POST['supplier']);
//update req2
db_query("UPDATE products SET required2=required2-'".$amount."' WHERE product_id='".$orderID."'", 'update_req');
//insert into supplier orders
db_query("INSERT INTO supplier_orders (supplier_id,product_id,amount,price,norm_order) VALUES ('".$supplier."','".$orderID."','".$amount."','".$buy_price."','1')", 'supplier_order');
echo 'O='.$orderID.',S='.$supplier.',A='.$amount.',P='.$buy_price.'<br />';
}
It's passed from a variables such as :
Code: Select all
<td align="center"><input type="text" name="<?php echo 'amount['.$srow['product_id'].']'; ?>" id="amount" size="3"></td>
<td align="center">£<input type="text" name="<?php echo 'buy_price['.$srow['product_id'].']'; ?>" id="buy_price" value="<?php echo ''.$srow['buy_price'].''; ?>" size="3"></td>
<td align="center"><input type="checkbox" name="<?php echo 'order['.$srow['product_id'].']'; ?>" id="order"></td>
<td align="center"><input type="checkbox" name="<?php echo 'backorder['.$srow['product_id'].']'; ?>" id="backorder"></td>
<td align="center">
For some reason it only works as it should if the top order variable is ticked before posting. If the top one in the list isn't ticked it doesn't post any of the other information apart from the order variable. Any ideas?
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 3:26 am
It seems to be when one tick is missing in the order list of boxes.
So if i tick the 1st and 2nd it works, if i tick the 1st and 3rd then only the 1st will work. Really need this to work asap, anyone any ideas ?
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Sep 12, 2006 3:33 am
Geshi really doesn't like embedded php :\
Instead of creating text boxes with names like "order[123]" just create a hidden field for the ID, then use single element names for 'order', 'backorder' etc.
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 3:36 am
You mean loop through the hidden field with the foreach?
If i have a hidden field for the id, how does it know to which rows have been ticked when all $_POST['order'] would be the same?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Sep 12, 2006 3:38 am
Wouldn't it be a lot easier if you name your input elements like
Code: Select all
wo[$product_id][amount]
wo[$product_id][buy_price]
wo[$product_id][order]
wo[$product_id][backorder]?
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 3:40 am
Sorry if i'm a bit thick here, but how would i use those variables?
I need to create a query using them. There is a table with one row having one instance of each variable. I need to loop through each row of posted variables and input them as a query.
In a rush to get this done, as i'll be leaving the project soon and it needs to be done today.
Will be very grateful if you guys can help me find a solution to this.
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 4:56 am
Tried various methods and can't get it to work.
Just need to know how to pass lots of variables though in sets.
So say i have:
order (tickbox), amount, buy price
and there can be say 10 rows of those all posted. I need to know how to get each row on it's own so i can build a query.