Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选择在CodeIgniter中显示MySQL DB值的位置_Php_Mysql_Codeigniter - Fatal编程技术网

Php 选择在CodeIgniter中显示MySQL DB值的位置

Php 选择在CodeIgniter中显示MySQL DB值的位置,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想使用CodeIgniter显示MySQL数据库中的值。这里,我使用SELECT查询,以使用WHERE条件比较多个值 我想将选中的行值从一页显示到另一页。我通过URL传递选中的值。在第二页中,我从URL获取值,并使用explode()函数拆分值,并使用for循环显示。在这里,值显示正确。但是,当将数组值传递给SELECT查询时,它只显示最后一行 我想显示数据库中所有选中的行 例如,示例代码: <?php $id = $this->uri->segment(4); $arr

我想使用CodeIgniter显示MySQL数据库中的值。这里,我使用
SELECT
查询,以使用
WHERE
条件比较多个值

我想将选中的行值从一页显示到另一页。我通过URL传递选中的值。在第二页中,我从URL获取值,并使用
explode()
函数拆分值,并使用
for
循环显示。在这里,值显示正确。但是,当将数组值传递给
SELECT
查询时,它只显示最后一行

我想显示数据库中所有选中的行

例如,示例代码:

<?php

$id  = $this->uri->segment(4);
$arr = explode(',', $id);
for ($kk = 0; $kk < count($arr); $kk++) {
    echo $id_val13 = $arr[$kk];
    $basicUrl                = $this->config->item("basicUrl");
    $basicUrl['bread_crumb'] = $this->breadcrumb();
    $query                   = $this->db->query("SELECT aa.id as id,customer_type_id,start_time,close_time,dd.name as customer_name,bb.name as vehicle_name,cc.name as driver_name,other_expensive,depature_city,destination_city,journey_status,payment,tour_file,DATE_FORMAT(aa.created_date, '%d/%m/%Y') as created_date FROM " . $this->tbl . " as aa
                                left join vehicle as bb on aa.vehicle_id=bb.id
                                left join driver as cc on aa.driver_id=cc.id
                                left join tbl_customer as dd on aa.customer_id=dd.id
                                WHERE aa.id = $id_val13");

    $result = array();

    if ($query->num_rows()) {
        $i = 1;
        foreach ($query->result() as $row) {
            $result_row   = array();
            $result_row[] = '<input type="checkbox" name="chk_id" id="chk_id" value="' . $row->id . '" />';
            $result_row[] = $row->id;
            $result_row[] = $row->customer_name;
            if ($row->customer_type_id == "1")
                $result_row[] = "Tour";
            else if ($row->customer_type_id == "2")
                $result_row[] = "Company";
            else if ($row->customer_type_id == "3")
                $result_row[] = "Guest";
            $result_row[] = $row->driver_name;
            $result_row[] = $row->vehicle_name;

            $result_row[] = $row->destination_city;
            $result_row[] = $row->start_time;
            $result_row[] = $row->close_time;
            $result_row[] = $row->payment;
            $result_row[] = $row->other_expensive;
            $result_row[] = $row->journey_status == "1" ? "Complete" : "On Progress";
            if ($row->tour_file != "") {
                $result_row[] = '<a href="' . base_url('uploads/' . $row->tour_file) . '">' . $row->tour_file . '</a>';
            } else {
                $result_row[] = "No File";
            }
            $result_row[] = $row->created_date;
            $action_btn   = action_button("Edit", $row->id) . action_button("Delete", $row->id) . action_button("Select", $row->id);
            $result_row[] = $action_btn;

            $result[] = $result_row;

            $i++;                                
        }                        
    }                
}


$tbl_header = array(
    "",
    "S NO",
    "Customer Name",
    "Type",
    "Driver Name",
    'Vehicle Name',
    "Destination City",
    "Start Time",
    "Close Time",
    "Rupee",
    "Other Expensive",
    "Journey Status",
    "Itinerary",
    "Created Date",
    array(
        "Edit",
        "Delete"
    )
);
$basicUrl['table'] = $this->makeTable($result, $tbl_header, $bool = TRUE);

$this->parser->parse("admin/center", $basicUrl);

?>
通常使用
explode()
for
循环,它会显示所有值。当我使用CodeIgniter使用select查询时,它只显示最后一行。

试试这个(我在for循环之前定义了
$result
),而且像这样使用代码使用控制器和模型来完成所有逻辑和数据库工作也不是一个好的做法

 <?php

    $id = $this->uri->segment(4);
    $arr = explode(',', $id);
    $result=array();
    for ($kk = 0; $kk < count($arr); $kk++)
        {
          echo $id_val13 =  $arr[$kk];
            $basicUrl = $this->config->item("basicUrl");
            $basicUrl['bread_crumb'] = $this->breadcrumb();
            $query=$this->db->query("SELECT aa.id as id,customer_type_id,start_time,close_time,dd.name as customer_name,bb.name as vehicle_name,cc.name as driver_name,other_expensive,depature_city,destination_city,journey_status,payment,tour_file,DATE_FORMAT(aa.created_date, '%d/%m/%Y') as created_date FROM ".$this->tbl." as aa
                            left join vehicle as bb on aa.vehicle_id=bb.id
                            left join driver as cc on aa.driver_id=cc.id
                            left join tbl_customer as dd on aa.customer_id=dd.id
                            WHERE aa.id = $id_val13"); 


    if($query->num_rows()){
        $i=1;
        foreach($query->result() as $row){
            $result_row=array();
            $result_row[]='<input type="checkbox" name="chk_id" id="chk_id" value="'.$row->id.'" />';
            $result_row[]=$row->id;
            $result_row[]=$row->customer_name;
            if($row->customer_type_id=="1")
            $result_row[]="Tour";
            else if($row->customer_type_id=="2")
            $result_row[]="Company";
            else if($row->customer_type_id=="3")
            $result_row[]="Guest";
            $result_row[]=$row->driver_name;
            $result_row[]=$row->vehicle_name;

            $result_row[]=$row->destination_city;
            $result_row[]=$row->start_time;
            $result_row[]=$row->close_time;
            $result_row[]=$row->payment;
            $result_row[]=$row->other_expensive;
            $result_row[]=$row->journey_status=="1" ? "Complete" : "On Progress";
            if($row->tour_file!="")
            {
            $result_row[]='<a href="'.base_url('uploads/'.$row->tour_file).'">'.$row->tour_file.'</a>';
            }
            else
            {
            $result_row[]="No File";
            }
            $result_row[]=$row->created_date;
            $action_btn=action_button("Edit",$row->id).action_button("Delete",$row->id).action_button("Select",$row->id);
            $result_row[]=$action_btn;

            $result[]=$result_row;


            $i++;


    }


        }


         }


        $tbl_header=array("","S NO","Customer Name","Type","Driver Name",'Vehicle Name',"Destination City","Start Time","Close Time","Rupee","Other Expensive","Journey Status","Itinerary","Created Date",array("Edit","Delete"));
    $basicUrl['table']=$this->makeTable($result,$tbl_header,$bool=TRUE);

    $this->parser->parse("admin/center",$basicUrl);


     ?>

 <?php

    $id = $this->uri->segment(4);
    $arr = explode(',', $id);
    $result=array();
    for ($kk = 0; $kk < count($arr); $kk++)
        {
          echo $id_val13 =  $arr[$kk];
            $basicUrl = $this->config->item("basicUrl");
            $basicUrl['bread_crumb'] = $this->breadcrumb();
            $query=$this->db->query("SELECT aa.id as id,customer_type_id,start_time,close_time,dd.name as customer_name,bb.name as vehicle_name,cc.name as driver_name,other_expensive,depature_city,destination_city,journey_status,payment,tour_file,DATE_FORMAT(aa.created_date, '%d/%m/%Y') as created_date FROM ".$this->tbl." as aa
                            left join vehicle as bb on aa.vehicle_id=bb.id
                            left join driver as cc on aa.driver_id=cc.id
                            left join tbl_customer as dd on aa.customer_id=dd.id
                            WHERE aa.id = $id_val13"); 


    if($query->num_rows()){
        $i=1;
        foreach($query->result() as $row){
            $result_row=array();
            $result_row[]='<input type="checkbox" name="chk_id" id="chk_id" value="'.$row->id.'" />';
            $result_row[]=$row->id;
            $result_row[]=$row->customer_name;
            if($row->customer_type_id=="1")
            $result_row[]="Tour";
            else if($row->customer_type_id=="2")
            $result_row[]="Company";
            else if($row->customer_type_id=="3")
            $result_row[]="Guest";
            $result_row[]=$row->driver_name;
            $result_row[]=$row->vehicle_name;

            $result_row[]=$row->destination_city;
            $result_row[]=$row->start_time;
            $result_row[]=$row->close_time;
            $result_row[]=$row->payment;
            $result_row[]=$row->other_expensive;
            $result_row[]=$row->journey_status=="1" ? "Complete" : "On Progress";
            if($row->tour_file!="")
            {
            $result_row[]='<a href="'.base_url('uploads/'.$row->tour_file).'">'.$row->tour_file.'</a>';
            }
            else
            {
            $result_row[]="No File";
            }
            $result_row[]=$row->created_date;
            $action_btn=action_button("Edit",$row->id).action_button("Delete",$row->id).action_button("Select",$row->id);
            $result_row[]=$action_btn;

            $result[]=$result_row;


            $i++;


    }


        }


         }


        $tbl_header=array("","S NO","Customer Name","Type","Driver Name",'Vehicle Name',"Destination City","Start Time","Close Time","Rupee","Other Expensive","Journey Status","Itinerary","Created Date",array("Edit","Delete"));
    $basicUrl['table']=$this->makeTable($result,$tbl_header,$bool=TRUE);

    $this->parser->parse("admin/center",$basicUrl);


     ?>