Snuur
Snuur

Reputation: 309

mysql subquery in large insert query

I need to make a subquery in a large query, but am unsure on how to implement this with many other predefined values involved. Lots of examples just show 2 rows that are both obtained trough the subquery.

Can anyone explain to me how to check for the last 'ordernummer' add that with +1 and use that value in the insert query?

INSERT INTO orderheaders (user, timestamp, ipadres, ordernummer, ordernummer_cash, offertenummer, debnr, contact, referentie, quantity, totaal, paymethod, shipmethod, paymentkey, bank_id) 
VALUES ('".$user."', '".time()."', '".$_SERVER['REMOTE_ADDR']."', '".$ordernummer."',$ordernummer,'".$_POST['offertenummer']."','".$newdeb."', '".$newcontact."', '".$_POST['referentie']."', '".$total_qty_prods."', '".$totaal."', '".$paymethod."', '".$shipping."', '".$paymentkey."', '')

so for $ordernummer I need to get the value of

SELECT ordernummer FROM orderheaders ORDER BY id DESC LIMIT 0,1

Upvotes: 0

Views: 76

Answers (1)

Hadiyal Rakesh
Hadiyal Rakesh

Reputation: 249

Check this Solutions I think you want last order no +(plus) 1 and direct insert records $ordernummer = 1;

INSERT INTO orderheaders (
    user, timestamp, ipadres, 
    ordernummer, ordernummer_cash, offertenummer, 
    debnr, contact, referentie, 
    quantity, totaal, paymethod, 
    shipmethod, paymentkey, bank_id 
) VALUES (
    '".$user."', '".time()."', '".$_SERVER['REMOTE_ADDR']."', '"
    .$ordernummer."',ordernummer + $ordernummer,'".$_POST['offertenummer']."','"
    .$newdeb."', '".$newcontact."', '".$_POST['referentie']."', '"
    .$total_qty_prods."', '".$totaal."', '".$paymethod."', '"
    .$shipping."', '".$paymentkey."', ''
)

Upvotes: 1

Related Questions