abs0lut Posted May 1, 2008 Share Posted May 1, 2008 database structure ctable iqtable 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 More sharing options...
mrdamien Posted May 2, 2008 Share Posted May 2, 2008 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? Link to comment https://forums.phpfreaks.com/topic/103785-insert-multiple-rows/#findComment-531392 Share on other sites More sharing options...
abs0lut Posted May 2, 2008 Author Share Posted May 2, 2008 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 More sharing options...
moselkady Posted May 2, 2008 Share Posted May 2, 2008 Try something like this: if ($usb_cost > 0) mysql_query("INSERT INTO ctable (iqid,cost) VALUES((SELECT iqid FROM iqtable WHERE name='usb'),$usb_cost); Link to comment https://forums.phpfreaks.com/topic/103785-insert-multiple-rows/#findComment-531501 Share on other sites More sharing options...
abs0lut Posted May 2, 2008 Author Share Posted May 2, 2008 also, name varies.. quantity and names are posted by the admin.. why SELECT iqid FROM iqtable WHERE name='usb' ?? Link to comment https://forums.phpfreaks.com/topic/103785-insert-multiple-rows/#findComment-531575 Share on other sites More sharing options...
moselkady Posted May 2, 2008 Share Posted May 2, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.