PHP&SQL WHERE(更改变量) [英] PHP & SQL WHERE (changing variable)

查看:59
本文介绍了PHP&SQL WHERE(更改变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我正在为这段代码而苦苦挣扎.
结果"10"设置为$ fod,但是需要替换它以显示被调用行的ID,以便SQL WHERE可以在相关行中列出正确的数据.有关获得的结果,请参见图像.

Good Day, i'm struggling with this code..
The result "10" is set $fod but this needs to be replaced to display the called row's id so that the SQL WHERE can list the correct data inside the relevant row. See Image for the Result i'm getting.

查看当前结果和所需结果
如您所见,我需要ROW ID 10来显示10的项目,而ROW ID 11来显示11的项目.请协助我,如何调用这些行才能正确显示?
调用函数:
Controller.php

See Current Result and Desired Result
As you can see i need ROW ID 10 to display 10's items and ROW ID 11 to display 11's items. Please assist me, how can i call these rows to display correctly?
Calling function:
Controller.php

$data['order_list'] = $this->product->data_ordershalf();
$fod = 10;
$data['order_listfull'] = $this->product->data_ordersfull($fod);

Functions.php:

Functions.php:

function data_ordershalf(){
    $this->db->select('*');
    $this->db->join('order_detail', 'order_detail.orderid=orders.id', 'left');
    $this->db->join('customers', 'customers.id=orders.customerid', 'left');
    $this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
    $this->db->from('orders');
    $this->db->group_by('orderid');
    $rs = $this->db->get();
    return $rs->result_array();
}
function data_ordersfull($fod){
    $this->db->select('*');
    $this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
    $this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
    $this->db->from('order_detail');
    $this->db->where('orderid',$fod);
    $rs = $this->db->get();
    return $rs->result_array();

View.php:

<?php if(!$order_list){ ?>
<tbody>
    <tr>
        <th colspan="7"><center>No orders placed</center></th>
    </tr>
</tbody>
<?php } else { $sr = 1; ?>
<tbody>
    <?php foreach( $order_list as $row) { ?>
    <tr>
        <th scope="row"><?php echo $row['id']; ?></th>
        <td><?php echo $row['date']; ?></td>
        <td><?php echo $row['name']; ?></td>
        <td>
            <table>
                <?php foreach( $order_listfull as $row2) { ?>
                <tr>
                    <th scope="row"><?php echo $row2['id']; ?></th>
                    <td><?php echo $row2['product_name']; ?></td>
                    <td><?php echo $row2['quantity']; ?></td>
                    <td></td>
                    <td><?php echo $row2['price']; ?></td>
                 </tr>
                <?php } ?>
            </table>
        </td>
        <td><?php echo $row['quantity']; ?></td>
        <td><?php echo $row['price']; ?></td>
    </tr>
    <?php } ?>
</tbody>
<?php } ?>

推荐答案

您可以创建帮助程序并为其添加以下功能.

You can create helper and put following function it.

function data_ordersfull($fod){
    $this->db->select('*');
    $this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
    $this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
    $this->db->from('order_detail');
    $this->db->where('orderid',$fod);
    $rs = $this->db->get();
    return $rs->result_array();
}

==================== View.php =======================================

====================View.php======================================

<?php if(!$order_list){ ?>
            <tbody>
              <tr>
                <th colspan="7"><center>No orders placed</center></th>
              </tr>
            </tbody>
            <?php } else { $sr = 1; ?>
            <tbody>
              <?php foreach( $order_list as $row) { 
$order_listfull=data_ordersfull($row['id']);
?>
              <tr>
                <th scope="row"><?php echo $row['id']; ?></th>
                <td><?php echo $row['date']; ?></td>
                <td><?php echo $row['name']; ?></td>
                <td><table>
              <?php foreach( $order_listfull as $row2) { ?>
              <tr>
                <th scope="row"><?php echo $row2['id']; ?></th>
                <td><?php echo $row2['product_name']; ?></td>
                <td><?php echo $row2['quantity']; ?></td>
                <td></td>
                <td><?php echo $row2['price']; ?></td>

              </tr>
              <?php } ?></table></td>
                <td><?php echo $row['quantity']; ?></td>
                <td><?php echo $row['price']; ?></td>

                  </tr>
                  <?php } ?>
                </tbody>
                <?php } ?>

这篇关于PHP&amp;SQL WHERE(更改变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆