Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3968226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:49:00+00:00 2026-05-20T03:49:00+00:00

$q4 = SELECT order_id FROM menu WHERE category_id = $cat_id; $r4 = mysqli_query($dbc, $q4);

  • 0
$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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:49:01+00:00Added an answer on May 20, 2026 at 3:49 am

    A. using composite primary key on category_id, order_id, and build an auto increment on that, like

    create table menu
    (
      category_id int(10) unsigned default 0,
      order_id int(10) unsigned auto_increment,
      item int(10) unsigned default 0,
      price double(10, 2) unsigned default 0,
      date_added datetime,
      name varchar(255),
      primary key(category_id, order_id)
    );
    

    B: use a sub-query during insert, like

    insert into menu
    (category_id, item, price, date_added, name, order_id)
    select 
      $category_id as category_id, 
      $item as item, 
      $price as price, 
      now() as date_added, 
      $name as name,
      (select max(order_id) from menu where category_id=$category_id)+1 as order_id
    from dual;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert a value from the database into my dropdown menu in
For this query SELECT min(date) min_date FROM order_products group by order_id min_date ignores the
I'm building a Zend form that has a dropdown/select menu populated with data from
My current method is this: SELECT TOP 1 ID FROM DATAENTRY ORDER BY ID
I use this $query = SELECT * FROM info ORDER BY id DESC limit
This is my code: $query = mysql_query(SELECT * FROM books ORDER BY id) or
I have a MySQL query SELECT * FROM 'redirect' WHERE 'user_id'= \''.$_SESSION['user_id'].' \' ORDER
SELECT * FROM tbl_order_head AS o INNER JOIN tbl_orders_log AS c ON o.PAYMENT_TRANSACTION_LOG_ID=c.TRANSACTION_ID WHERE
SELECT * FROM (SELECT ROW_NUMBER() over ( ORDER BY CASE WHEN @SortExpression ='Country_id' THEN
$sql = select body, stamp from posts where user_id = '$userid' order by stamp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.