piznac Posted July 10, 2007 Share Posted July 10, 2007 Prehaps this is a backwards way of doing this. So if Im being dense please don't hesitate to say so. So here is what I have: function insert_multi($item_num,$item_desc,$item_qty,$emb_loc1,$num,$size,$artwork){ $flds = array( 'item_num' , 'item_desc' , 'item_qty', 'num', 'size'); for($i=0;$i<count($_POST['item_qty']);$i++) { $qtmp = array(); foreach($flds as $fld) if (trim(stripslashes($_POST[$fld][$i])) != '') $qtmp[] = $fld . " = '" . mysql_escape_string(trim(stripslashes($_POST[$fld][$i]))) . "'"; $q = "insert into c_or_details set " . implode(', ',$qtmp); $rs = mysql_query($q) or die ('Problem with 1 the query: ' . $q . '<br>' . mysql_error()); } } As you can see Im inserting an indermined amount of records into a mysql table. Next I need to insert the remaining data "$artwork & $emb_loc1" into another table. Which dosent really pose a problem. But with each entry of the last sql statement an auto increment value defines each entry. I need that auto number to insert with the other data into the new table. Does that make sense. Basically I have a main table and a sub table. The main table holds the main data on an order. The sub table holds "options" of the order. But to be able to pull them back I need a primary key to match the key in the main table. Anyone know an easy way to get this data from the first table to the other? Quote Link to comment Share on other sites More sharing options...
piznac Posted July 10, 2007 Author Share Posted July 10, 2007 I suppose I could do a query before the insert to see what is the last auto number. Then count the number of inserts and add one to each (incrementally) and then use those numbers. This seems highly inaccurate though,.. is there a better way? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 www.php.net/mysql_insert_id Quote Link to comment Share on other sites More sharing options...
piznac Posted July 10, 2007 Author Share Posted July 10, 2007 Yeah I was looking at that,.. but dosent that return the number for the last one? What if I inserted like 100 at a time? Would that just return the last one. I would need the numbers from all 100. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 <?php foreach ($insert_array as $insert) { mysql_query($insert); $ids[] = mysql_insert_id(); } print_r($ids); ?> Simple as that given that each insert is in an array or looped through some how. Quote Link to comment Share on other sites More sharing options...
piznac Posted July 10, 2007 Author Share Posted July 10, 2007 ok,.. that should work,. wow always something simple..LOL.. Thanks man., Let me give this a go. I don't want to mark it as solved untill I can place the code up though Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.