SQL Query - Array но Specifi c В столбце отображается только 1 раз - PullRequest
0 голосов
/ 10 апреля 2020

Модель

$sql = "
SELECT  op.name 
     , op.price 
     , op.quantity 
     , o.order_cancel_remark  
  FROM order_product op 
  LEFT 
  JOIN `order` o 
    ON o.order_id = op.order_id 
  LEFT 
  JOIN `order_product_history` oph 
    ON oph.`order_product_id` = op.`order_product_id` 
   AND oph.`current_status` = 1 
  LEFT 
  JOIN `order_status` os 
    ON os.`order_status_id` = oph.`order_status_id` 
   AND os.`language_id` = 1 
 WHERE o.order_id = '" . (int)$order_id . "'";

$query = $this->db->query($sql);

return $query->rows;

Контроллер

    $data['orderP_results'][] = array(

        'name'      => $order_price_result['name'] ,
        'price'     => number_format($order_price_result['map'],2,'.',''),
        'quantity'  => $order_price_result['quantity'],
        'sku'       => $order_price_result['sku'],
         'order_cancel_remark'      => $order_price_result['order_cancel_remark'],
        'total'     => number_format($order_price_result['map'] * $order_price_result['quantity'],2,'.',''),

    );

Просмотр страницы

     {% if orderP_results %}
            {% for orderP_result in orderP_results %}
              {{orderP_result.order_cancel_remark}}
            <table class="d">
            <tr>
                <th>        <legend style="padding-top:10px;">Product Image</legend></th>
                <th>    <legend style="padding-top:10px;">Product Name</legend></th>
                <th>        <legend style="padding-top:10px;">Product SKU</legend></th>
            </tr>
            <tr>
                <td>    <img src="{{orderP_result.image}}"></td>
                    <td>    <b class="color-bold">{{orderP_result.name}}</b> </td>
                        <td>        SKU: <b class="color-bold">{{orderP_result.sku}}</b></td>
            </tr>
        </table>

Просмотр страницы: https://prnt.sc/rwghyo

То, что я хотел: для «Отмена заказа заказа» отображается только 1 раз вместо нескольких (в зависимости от строк)

Пример (это то, что я хотел): https://prnt.sc/rwgi8u

Ответы [ 2 ]

0 голосов
/ 10 апреля 2020

К вашему сведению, ваш запрос функционально идентичен следующему:

SELECT  op.name 
 , op.price 
 , op.quantity 
 , o.order_cancel_remark  
  FROM order_product op  
  JOIN `order` o 
    ON o.order_id = op.order_id 
  WHERE o.order_id = '" . (int)$order_id . "'";
0 голосов
/ 10 апреля 2020

По вашему мнению, удалите order_cancel_remark из for для l oop и добавьте его снаружи для отображения только один раз

{% if orderP_results %}
            {{orderP_result[0].order_cancel_remark}}
            {% for orderP_result in orderP_results %}
            <table class="d">
            <tr>
                <th>        <legend style="padding-top:10px;">Product Image</legend></th>
                <th>    <legend style="padding-top:10px;">Product Name</legend></th>
                <th>        <legend style="padding-top:10px;">Product SKU</legend></th>
            </tr>
            <tr>
                <td>    <img src="{{orderP_result.image}}"></td>
                    <td>    <b class="color-bold">{{orderP_result.name}}</b> </td>
                        <td>        SKU: <b class="color-bold">{{orderP_result.sku}}</b></td>
            </tr>
        </table>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...