 |
|
คิวรี่แล้วฟิลด์ sel ข้อมูลออกมาไม่หมดครับ ตามจริงจะต้องออก
lenovo ต้อง 1,2,3,...,30(30) อันนี้ครบ
ที่ไม่ครบคือ
ipad ต้อง 1,2,3,...,25(25) แต่มาแค่ 1,2,3,4,5,(25)
และ surface ต้อง 1,2,3,...,15(15) แต่ไม่มีข้อมูลออกมาเลย
ไม่แน่ใจว่าผิดตรงไหน 



อันนี้โค้ด ตัดคำเอาแค่ตัวท้ายก่อนวงเล็บมาต่อกัน ตามรูป
Code (PHP)
while($data = $sql->fetch(PDO::FETCH_ASSOC)) {
$i++;
$arr = array();
$arr[] = $data['sel'];
} //while
$ex = explode(',', $arr[0]);
$txt = array();
$array_ipad = array();
$array_lenovo = array();
$array_surface = array();
$lenovo = array();
$ipad = array();
$surface = array();
foreach ($ex as $key => $val) {
$txt = explode('-', $ex[$key]);
if ($txt[0] == '121/54') {
$array_lenovo = explode('(', $txt[4]);
// $c = $b[0];
array_push($lenovo, $array_lenovo[0]);
}
if ($txt[0] == '1155') {
$array_ipad = explode('(', $txt[7]);
// $c = $b[0];
array_push($ipad, $array_ipad[0]);
}
if ($txt[0] == '1159') {
$array_surface = explode('(', $txt[4]);
// $c = $b[0];
array_push($surface, $array_surface[0]);
}
}
$str_count_lenovo = count($lenovo)-1;
$code_lenovo = "คอมพิวเตอร์พกพา Lenovo รหัสครุภัณฑ์ 121/54-1312-060-03-";
foreach ($lenovo as $key => $value) {
if ($str_count_lenovo == $key) {
$code_lenovo .= $value;
}
else {
$code_lenovo .= $value.',';
}
}
$code_lenovo .= "(30)";
//echo $code_lenovo."<br>";
$str_count_ipad = count($ipad)-1;
$code_ipad = "Apple ipad รหัสครุภัณฑ์ 1155-1312-025-43-1(1)/7-1(1)/2-1(1)/13-";
foreach ($ipad as $key => $value) {
if ($str_count_ipad == $key) {
$code_ipad .= $value;
}
else {
$code_ipad .= $value.',';
}
}
$code_ipad .= "(25)";
//echo $code_ipad."<br>";
$str_count_surface = count($surface)-1;
$code_surface = "Microsoft surface รหัสครุภัณฑ์ 1159-1312-060-08-";
foreach ($surface as $key => $value) {
if ($str_count_surface == $key) {
$code_surface .= $value;
}
else {
$code_surface .= $value.',';
}
}
$code_surface .= "(15)/มทร.11ค/งปม.2559";
//echo $code_surface;
SQL
Code (SQL)
SELECT
(SELECT GROUP_CONCAT(code ORDER BY machine_id SEPARATOR ',')
FROM tbl_machine
WHERE FIND_IN_SET(tbl_machine.machine_id,GROUP_CONCAT(tbl_select_item.machine)) ) AS sel,
tbl_borrow_logs.`user`,
tbl_borrow_logs.fullname,
tbl_borrow_logs.log_id,
tbl_borrow_logs.depart,
tbl_select_item.amount,
tbl_borrow_logs.tel1,
tbl_borrow_logs.tel2,
tbl_borrow_logs.obj,
tbl_borrow_logs.logs_status,
tbl_borrow_logs.loan_by,
tbl_borrow_logs.approve_by,
tbl_borrow_logs.start_date,
tbl_borrow_logs.end_date,
tbl_borrow_logs.date_receive,
tbl_borrow_logs.date_return,
tbl_borrow_logs.place,
tbl_borrow_logs.signature_user,
tbl_borrow_logs.signature_admin,
tbl_borrow_logs.signature_super_admin,
tbl_borrow_logs.return_signature_user,
DATEDIFF(end_date, start_date) AS totalday,
DATE_FORMAT(start_date, '%d') AS thaidate,
DATE_FORMAT(start_date, '%Y') + 543 AS thaiyear,
DATE_FORMAT(start_date, '%H.%i') AS thaitime,
DATE_FORMAT(end_date, '%d') AS thaidate2,
DATE_FORMAT(end_date, '%Y') + 543 AS thaiyear2,
DATE_FORMAT(end_date, '%H.%i') AS thaitime2,
DATE_FORMAT(date_receive, '%d') AS thaidate3,
DATE_FORMAT(date_receive, '%Y') + 543 AS thaiyear3,
DATE_FORMAT(date_receive, '%H.%i') AS thaitime3,
DATE_FORMAT(date_return, '%d') AS thaidate4,
DATE_FORMAT(date_return, '%Y') + 543 AS thaiyear4,
DATE_FORMAT(date_return, '%H.%i') AS thaitime4,
tbl_select_item.machine
FROM
tbl_borrow_logs
INNER JOIN tbl_select_item ON tbl_borrow_logs.log_id = tbl_select_item.logs_id
WHERE
log_id = 1
GROUP BY
date_borrow
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2017-03-30 15:59:36 |
By :
littlebeer |
View :
1319 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |