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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:08:18+00:00 2026-06-13T14:08:18+00:00

I got a Bash/PHP script that retrieves records from a table called ‘assess_2012’ and

  • 0

I got a Bash/PHP script that retrieves records from a table called ‘assess_2012’ and stores records that need to be written to a table called ‘assess_2012_err’ in a multidimensional array:

#!/usr/bin/php -q

<?php
$host = "localhost";
$user = "username";
$pass = "password";
$name = "reassess";

$conn = mysqli_connect($host, $user, $pass, $name) OR die ("Could not connect to database: " . mysqli_error($conn) . "\n");

$q = "SELECT su_id, ass_date, ind_d FROM assess_2012";
$r = mysqli_query ($conn, $q);

if ($r) {
    while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

        // Check for errors:
        if ($row['ind_d'] == 'Y') {
            // Add to the array:
            $sql[] = array('su_id' => $row['su_id'], 'err_code' => 1);
        }
    }
    var_dump($sql);
}
else {
    // SELECT query failed:
    echo "Error: " . mysqli_error($conn) . "\n";
}
?>

The ‘var_dump’ looks like this (shortened version – the actual query returns hundreds of records):

array(1) {
  [0]=>
  array(2) 
    ["su_id"]=>
    string(1) "5"
    ["err_code"]=>
    int(1)
  }
  [1]=>
  array(2) {
    ["su_id"]=>
    string(4) "1492"
    ["err_code"]=>
    int(1)
  }
}

What I can’t figure out is how I can use the array to produce a query like this:

INSERT INTO assess_2012_err (su_id, err_code) VALUES (5, 1), (1492, 1)
  • 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-06-13T14:08:18+00:00Added an answer on June 13, 2026 at 2:08 pm

    You’ll be better off doing one by one, like so

    foreach($sql as $variables)
    {
      // Insert here: 
      INSERT INTO asses_2012_err (su_id, err_code) VALUES ($variables['su_id'], $variables['err_code']);
    
    }
    

    Some important things to bear in mind:

    • Treat those inputs as user inputs, sanitise them!
    • Try to use PDO as mysql_* functions are going to be deprecated
    • Consider a data abstraction layer (so all your queries are hidden away inside nice functions)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a PHP script that runs from bash/command line. It's passed variables that
I've got a bash script that reads input from a file like this: while
I got a variable in a bash script that I need to replace. The
I've got a bash script that uses ImageMagick to make thumbnail pictures from folder
I've got a bash script that can take arguments in a variety of different
I've got a little Bash script that I use to access twitter and pop
How do I execute an output piped from a bash script? I got this
I've currently got a bash script that parses /var/log/mail.log to determine the last login
I've got a script like: #!/bin/bash exec /usr/bin/some_binary > /tmp/my.log 2>&1 Problem is that
Let's say I've got a shell script called print_error.sh looking like this: #!/usr/bin/bash echo

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.