$q4 = "SELECT order_id FROM menu WHERE category_id = $cat_id";
$r4 = mysqli_query($dbc, $q4);
$num_items = mysqli_num_rows($r4)+1;
$q5 = "INSERT INTO menu (category_id, order_id, item, price, date_added, name) VALUES ('$cat_id', '$num_items', '$item', $price, NOW(), $name)";
$r5 = mysqli_query($dbc, $q5);
As of right now im doing one initial query to get the total amount of rows in the table so I can add the right order_id to the newly inserted row.
Basically, I want to retain the 1,2,3,4 so I the user can edit the order themselves
Is there a way to do this in one query? Or perhaps you guys know a better method?
Thanks
A. using composite primary key on
category_id, order_id, and build an auto increment on that, likeB: use a sub-query during insert, like