Answer the question
In order to leave comments, you need to log in
How to write an Opencart SQL query correctly?
Now I take all the information about the order from the oc_order table, these are: address, phone number, etc.
$result_for_sal = $this->db->query("SELECT * FROM oc_order_product WHERE order_id = (SELECT order_id FROM oc_order_product ORDER BY order_product_id DESC LIMIT 1)");
$fileName = $result_for_sal->row['order_id'].".sal";
$id = $result_for_sal->row['order_id'];
$result_for_base_sm = $this->db->query("SELECT * FROM oc_order WHERE order_id = '$id'");
$firstname = $result_for_base_sm->row["payment_firstname"].' '.$result_for_base_sm->row["payment_lastname"];
$telephone = $result_for_base_sm->row["telephone"];
$country = $result_for_base_sm->row["payment_country"];
$region = $result_for_base_sm->row["payment_zone"];
$city = $result_for_base_sm->row["payment_city"];
$address = $result_for_base_sm->row["payment_address_1"];
$email = $result_for_base_sm->row["email"];
$comment = $result_for_base_sm->row["comment"];
$points = $result_for_sals->row["points"];
$points = $result_for_salss->row["price"];
$sale_for = $result_for_base_sm->row["payment_method"];
$sale_for = strip_tags($sale_for);
$str = <<<EOD
[Client]
Name= $firstname
MPhone= $telephone
CPhone=
ZIP=
Country= $country
Region= $region
City= $city
Address= $address
EMail= $email
[Options]
SaleType=1
Comment= $comment
OrderNumber= $id
DeliveryCondition= $sale_for
ReserveDate=
EOD;
for($i = 0; $i<count($result_for_sal->rows); $i++) {
$points = $result_for_sal->rows[$i]['points'];
$price = $result_for_sal->rows[$i]['price'];
$counts = $result_for_sal->rows[$i]['quantity'];
$str .= <<<EOD
\n[$i]
GoodID=$points
Price=$price
Count=$counts
EOD;
}
$str = iconv("UTF-8", "Windows-1251", $str);
file_put_contents('Orders/'.$fileName,$str);
$points = $result_for_sal->rows[$i]['points'];
$price = $result_for_sal->rows[$i]['price'];
Answer the question
In order to leave comments, you need to log in
And what about opencart? When you make requests, the main thing is not to use anything, as the developers of this miracle did, but to think with your head.
Use nested queries or JOINs.
At first write "naked" requests. For example, in phpmyadmin. Then move those queries into code by replacing the data with variables.
If writing complex queries is not your forte, and this functionality will be rarely used, then just do 1-2 SELECT * for tables that contain points and price, and then combine 3 arrays in the code: your data, points and price.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question