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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:56:28+00:00 2026-06-17T15:56:28+00:00

I have two PHP/SQL functions and I am wondering how I would minify them.

  • 0

I have two PHP/SQL functions and I am wondering how I would minify them. I’d like to run the 3 insert commands as a single $import rather than three, but I am not sure how to minify it.

$import9="INSERT into wp_postmeta (meta_id,post_id,meta_key,meta_value) values(',','$data[37]','lower_electric_costs','$data[5]')";
$import10="INSERT into wp_postmeta (meta_id,post_id,meta_key,meta_value) values(',','$data[37]','cheapest_green_electric','$data[6]')";
$import11="INSERT into wp_postmeta (meta_id,post_id,meta_key,meta_value) values(',','$data[37]','contract_type','$data[11]')";

Its the same thing with my PRINT results – how would I minify this down?

mysql_query($import9) or die("mysql_error()");
print $import9."<br>";
mysql_query($import10) or die("mysql_error()");
print $import10."<br>";
mysql_query($import11) or die("mysql_error()");
print $import11."<br>";

I am still learning PHP/SQL and learning how to minify my code is an important part of it I think. If someone can just how me an example of what a minified version would look like, then I can probably take it from there.

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-06-17T15:56:28+00:00Added an answer on June 17, 2026 at 3:56 pm

    You could combine it into a single query as follows:

    $import9="
        INSERT into
            wp_postmeta
            (meta_id,post_id,meta_key,meta_value)
        values
            (',','$data[37]','lower_electric_costs','$data[5]'),
            (',','$data[37]','cheapest_green_electric','$data[6]'),
            (',','$data[37]','contract_type','$data[11]')
    ";
    

    However, you should use mysqli instead of mysql functions, as mysql functions are deprecated.

    mysqli_query($import9);
    

    It is also advised that you do not use INSERT queries with mysqli_query but rather use Prepared Statements for security reasons. You should check out PDO and Prepared Statements.

    First, create a PDO instance.

    $db = new PDO("mysql:host=localhost;port=3306;dbname=mydb", "username", "password");
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //Turn off prepared statement emulation too.
    

    With a prepared statement, you would prepare your statement with the server:

    $stmt = $db->prepare("
        INSERT into
            wp_postmeta
            (meta_id,post_id,meta_key,meta_value)
        values
            (?,?,?,?)
    ");
    

    With an array like:

    $values = array(
        array(',',$data[37], 'lower_electric_costs', $data[5]),
        array(',',$data[37], 'cheapest_green_electric', $data[6]),
        array(',',$data[37], 'contract_type', $data[11]),
    );
    

    Next, you’d issue a series of execute statements:

    foreach ($values as $v) {
        $stmt->execute($v);
    }
    

    Finally, close the statement so that more statements can be executed:

    $stmt->closeCursor();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two times in PHP and I would like to determine the elapsed
I am working on PHP and database MySQL. I have two tables in SQL
I have two PHP functions to calculate the relation between two texts. They both
I'm struggling with some SQL/php syntax issues here. I'm trying to write two functions.
I have merge two array with php function merge_recursive (both came from sql query)
I have two PHP apps which have twho class with the same name. -
I am confused with & and && . I have two PHP books. One
I have two folders php and perl . They contain index.php and index.pl ,
I have two files client.php and server.php. The client file send a HTTP request
I have two sessions in PHP: $_SESSION[session][key] = md5 ($token . $userAgent . $ip);

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.