如何使查询和php值更容易获得?

有一个关于我的代码的问题,我认为它不够快。我注意到注入此代码后,所有进程的速度都降低了:

if (!empty($data['price1']) && !empty($data['price2']) && !empty($data['price3']) && !empty($data['price4']) && !empty($data['price5']) && !empty($data['price6']) && !empty($data['price7']) && !empty($data['price8']) && !empty($data['price9']) && !empty($data['price10'])) {
    $query=$this->db->query("SELECT product_id from ".DB_PREFIX."product WHERE model='".$data['model']."' ");
        if($query->num_rows){
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price1'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='2' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price2'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='3' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price3'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='4' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price4'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='5' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price5'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='6' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price6'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='7' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price7'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='8' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price8'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='9' ");      
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price9'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='10' ");     
            $this->db->query("UPDATE ".DB_PREFIX."product_prices SET price='".$this->db->escape($data['price10'])."' WHERE product_id='".$query->row['product_id']."' and customer_group_id='11' ");        

        }
        else
        {
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price1']."',customer_group_id='2'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price2']."',customer_group_id='3'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price3']."',customer_group_id='4'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price4']."',customer_group_id='5'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price5']."',customer_group_id='6'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price6']."',customer_group_id='7'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price7']."',customer_group_id='8'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price8']."',customer_group_id='9'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price9']."',customer_group_id='10'");
            $this->db->query("INSERT INTO ".DB_PREFIX."product_prices SET product_id='".$product_id."',price='".$data['price10']."',customer_group_id='11'");
        }
}

我不擅长php编码,试图尽我所能,只是我认为可能有更新选定表或空表的更快方法-插入新值。尝试以其他方式执行操作,例如检查每个数据[price1],[price2]等,但这要慢得多,因此尝试以这种方式进行-仍在缓慢进行。

评论