0
我想使用CodeIgniter顯示來自MySQL數據庫的值。在這裏,我使用SELECT
查詢以使用WHERE
條件比較多個值。在CodeIgniter中選擇從MySQL DB顯示值的位置
我想顯示從一頁到另一頁的檢查行值。我通過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);
?>
例如:
$array = array("1","2","6");
通常使用explode()
和for
環,它顯示所有的值。當我使用CodeIgniter使用select查詢時,它僅顯示最後一行。
謝謝..它的工作 – user3839366
@ user3839366很高興爲你工作.... –