问题描述:

I have a bit of code that looks like so:

if($_POST['order_page_content'] == 'list'){

$m_html_obj = "<table>";

$m_html_obj .= "<tr><td>Order No.</td><td>Created On</td><td>Customer Name</td><td>Items</td><td>View</td>";

foreach($data as $d){

$order_info = $d[0];

$time = new DateTime($order_info->created_date);

$date = $time->format('j.n.Y');

$m_html_obj .= "<tr><td>".$order_info->order_id."</td><td>".$date."</td>";

$m_html_obj .= "<td>".$order_info->customer_name."</td><td>1</td>";

$m_html_obj .= "<td><form action='' method='POST'>";

$m_html_obj .= "<input type='hidden' name='order_page_content' value='info'/>";

$m_html_obj .= "<input type='hidden' name='order_id' value='$order_info->order_id'/>";

$m_html_obj .= "<input type='submit' value='View'/>";

}

$m_html_obj .= "</form></td></tr>";

}

This basically creates a list of orders and basic info in a table, it also creates a button in the last column of the table for each record which is used to view the whole invoice for whatever order's row its on. Like the image below:

So what i want is when a user clicks on the button it posts the order id and the type of content to be displayed and then the information for that order is shown.

Now i have it so the information can be shown... but in the post using firebug i can see that on clicking the button, instead of that rows order number being submitted on its own, ALL of the order numbers are being submitted.

Why is this happening and how do i fix it?

Im guessing its something to do with the foreach loop?

Thanks

网友答案:

Solved it, i stupidly had my end form and table row tags outside the foreach loop therefore creating on large form after the first loop!

网友答案:

You will have to give each button a name using, say, the order number. That way your program will know which one was clicked.

相关阅读:
Top