I’m working on a WordPress Plugin script which extends the plugin. So, my problem is, I have to deal with the database which is pretty inefficient because I have only the first normal form…

This is the reason, why I’m forced to get the values like this:

$details = $database->query("SELECT `meta_key`, `meta_value` FROM `6v8T0_postmeta` WHERE post_id = '$pid' AND (meta_key like '$price_meta' OR meta_key like '$price_old_meta' OR meta_key like '$link_meta' OR meta_key like '$shop_meta')");

        while($row_meta = $details->fetch_assoc()){
            if($row_meta["meta_key"] == $price_meta){
                $price = $row_meta["meta_value"];
            }elseif($row_meta["meta_key"] == $price_old_meta){
                $price_old = $row_meta["meta_value"];
            }elseif($row_meta["meta_key"] == $link_meta){
                $link = $row_meta["meta_value"];
            }elseif($row_meta["meta_key"] == $shop_meta){
                $shop = $row_meta["meta_value"];
            }else{
                fwrite($myfile, "Is not matching!n");
            }
        }
  1. My question now is, what is $database->query returning?
    Because I want to minimize my SQL queries I want to load all values I need in a two dimensional array and sort them afterwords.

Is that possible and if yes, how?

  1. Stack SQL queries? – I say multiple times Select, Delete and Insert in a loop. Is it possible to stack those statements and execute one query instant of 4? – And if yes, can I continue in my code with fetch_assoc() normally? – Because I’m not sure if this is possible if I stack Delete, Insert and Select…

  2. Are there any other ways to minimize SQL queries?

Greetings and Thank You!

Read more here: Minimize SQL Statements? – Stack SQL queries?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: