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 3693056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:19:59+00:00 2026-05-19T04:19:59+00:00

i need some help with inserting multiple rows from different arrays into my database.

  • 0

i need some help with inserting multiple rows from different arrays into my database.

I am making the database for a seating plan, for each seating block there is 5 rows (A-E) with each row having 15 seats.

my DB rows are seat_id, seat_block, seat_row, seat_number, therefore i need to add 15 seat_numbers for each seat_row and 5 seat_rows for each seat_block.

I mocked it up with some foreach loops but need some help turning it into an (hopefully single) SQL statement.

$blocks = array("A","B","C","D");
$seat_rows = array("A","B","C","D","E");
$seat_nums = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");

foreach($blocks as $block){

    echo "<br><br>";
    echo "Block: " . $block . " - ";

    foreach($seat_rows as $rows){

        echo "Row: " . $rows . ", ";

        foreach($seat_nums as $seats){
            echo "seat:" . $seats . " ";
        }

    }
}

Maybe there’s a better way of doing it instead of using arrays?
i just want to avoid writing an SQL statement that is over 100 lines long 😉

(im using codeigniter too if anyone knows of a CI specific way of doing it but im not too bothered about that)

  • 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-19T04:20:00+00:00Added an answer on May 19, 2026 at 4:20 am

    try

    <?php
    
        $blocks = array("A","B","C","D");
        $seat_rows = array("A","B","C","D","E");
        $seat_nums = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");
    
        foreach($blocks as $block){
            foreach($seat_rows as $rows){
                foreach($seat_nums as $seats){
                    $querys[] = "('" . $block "','" . $rows . "', '" . $seats . "' )";
                }
            }
        }
    
        $query_inserts = join ( ", ", $querys );
    
        $query = "
            INSERT INTO
                table
            ( block, rows, seats )
            VALUES
                " . $query_inserts . "
            ";
    
        mysql_query ($query);
    
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Parsing some data and inserting it into 3 tables from .NET. Using Table Valued
I need some help on something. I am reading some data from an Excel
I need some help to figure out how to add multiple fields, on a
I need to insert multiple records to different tables, the problem is that some
I need some help. I am bringing in a string from a custom field
I need help on how to get/display some informations from DB (MySQl) My current
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help with Activerecord Querying in a has_many :through association. Model: Job class
Need some help, please. I have a line of horizontal thumbnails loaded as ONE

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.