Jump to content

insert multiple rows?


abs0lut

Recommended Posts

39061130pv1.th.jpg

database structure

ctable

ctableiy5.th.jpg

iqtable

iqtablevd1.th.jpg

 

Quantity and names are stored in database iqtable,

usb, usb cable and avr have different iqids,

I want to insert iqid with their cost..

example if you enter a cost in the name usb, the computer will get the iqid of the name and insert them together with the cost you entered..

how will I get the iqid of the quantity and names??

please help me..

Link to comment
https://forums.phpfreaks.com/topic/103785-insert-multiple-rows/
Share on other sites

INSERT INTO tbl (id, other, example, fields, name) VALUES (1, 'a', 'b', 'c', (SELECT name FROM othertable WHERE iqid='4'));

 

Is this what you mean?

 

no, iqid varies..

the iqid of usb is different from the iqid of the avr..

the iqid of avr is different from the iqid of the usb cable..

the iqid of usb is different from the iqid of the usb cable..

if I enter a value in the input form cost, the computer will get the iqid of the name and insert them together with the cost I entered..

 

for example if the iqid of usb is 2, and I entered 250 in the input form cost,

the computer will insert them in database (ctable)..

and if the iqid of the avr is 4 and I entered 300 in the input form cost,

the computer will insert them in database (ctable)..

and so on...

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/103785-insert-multiple-rows/#findComment-531467
Share on other sites

 

I may be mistaken but this is what I understand. The form has 'usb' row where the user can enter the cost. I assume that the <INPUT> field for the usb's cost is called "usb_cost". So, the script checks if this field has a value and if it is the script fetches iqid for usb from iqtable then inserts that iqid and the cost into table ctable.

We can do the same for avr and usb cable. So the code could be like this:

<?php
$usb_cost        = $_GET['usb_cost'];
$usbcable_cost = $_GET['usbcable_cost'];
$avr_cost        = $_GET['avr_cost'];
if ($usb_cost > 0) mysql_query("INSERT INTO ctable (iqid,cost) VALUES((SELECT iqid FROM iqtable WHERE name='usb'),$usb_cost);
if ($usbcable_cost > 0) mysql_query("INSERT INTO ctable (iqid,cost) VALUES((SELECT iqid FROM iqtable WHERE name='usb cable'),$usbcable_cost);
if ($avr_cost > 0) mysql_query("INSERT INTO ctable (iqid,cost) VALUES((SELECT iqid FROM iqtable WHERE name='avr'),$avr_cost);
?>

Link to comment
https://forums.phpfreaks.com/topic/103785-insert-multiple-rows/#findComment-531765
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.