Jump to content

get assigned number from sql insert for another insert


piznac

Recommended Posts

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?

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?

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.