1 id for more items

故事扮演 提交于 2019-12-12 03:36:10

问题


I have a form request_form.php, that is manage Purchase Request Form for request item.

Purchase_Request_No : (automatic - autoincrement)
Date :
Dept :
Supplier :
Item_Request :
Example have a 5 row :
1.
2.
3.
4.
5.

I want to make once Purchase Request have 1 Purchase_Request_No.
Example :

Purchase_Request_No : 17
Date :25-Jul-2012
Dept :Production
Supplier :Microsoft
Item_Request :
1.Windows XP Professional
2.Keyboard
3.Mouse
4.LCD Monitor
5.Speaker

So, how can I make it with 1 Purchase_Request_No with item request more than 1 item(in this case I put 5 items)?

Anyone can help me ? Thanks for advance.


Hi all, back again now I already in coding the concept. It's successfully save the data into database, but still when insert 5 item, it submit the data per item per ID. Example :
Item 1 - Computer (Purchase No 1)
Item 2 - Mouse (Purchase No 2)
That I wanted is :
Item 1 - Computer (Purchase No 1)
Item 2 - Mouse (Purchase No 1)

and here it's my code : I using purchase no with autoincrement.

<?php
$conn = oci_connect("system", "dev01");
$n = $_POST['jum'];
for ($i=1; $i<=$n; $i++)
{
$dept=$_POST['dept'];
$date_request=$_POST['date_request'];
$supplier=$_POST['supplier'];   

$item=$_POST['item'.$i];    
$qty=$_POST['qty'.$i];  
$uprice=$_POST['uprice'.$i];    
$total=$_POST['total'.$i];  

$s = oci_parse($conn,
"insert into purchase_request(dept_id, supplier_id, date_request, item, qty, uprice, total_amount) values ('$dept', '$supplier', '$date_request', '$item'
, '$qty', '$uprice', '$total'
)");

$r = oci_execute($s);

oci_rollback($conn);

echo "Data was committed\n";
}
?>

Any idea ?


回答1:


Have three tables. One would contain the products:

id    Product
1     Windows XP Professional
2     Keyboard
3     Mouse
4     LCD Monitor
5     Speaker

another contains the requests:

id    request_date    dept       supplier
1     25-Jul-2012     Production Microsoft

The third maps the first two together

id  request_id  item_id
1   1           1
2   1           2
3   1           3
4   1           4
5   1           5

(Alternately, you could make the ids of the products prime numbers and store the items column as a multiple of the items. All you'd need to do is find the prime factors of the items column, and then you've got the list of items!*)

*For some reason, no one at work thinks this is a good idea.




回答2:


The best practice is to create two table say

Purchase
Purchase_Id (Primary Key)
Supplier_Id: (foreign key referring Supplier table)
Purchase_date: datetime

Purchase_Items_Details
purchase_item_id (primary key)
purchase_id (foreign key to Purchase table)
item_id (foreign key to Products/Items table)
qty (Quantity)

Where In Purchase table you will Enter only Basic Purchase detail and Details about purchase will be added to the Purchase_Items_Details



来源:https://stackoverflow.com/questions/11680950/1-id-for-more-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!