|
|
|
รบกวนผู้รู้ช่วยแก้ปัญหาหน่อยครับ เกิด Error งง มาก |
|
|
|
|
|
|
|
หน้าข้อมูลที่จะส่ง
Code (PHP)
<?
if (($_POST['dateS']!="") && ($_POST['dateE']!="")) {
$dateS=$_POST['dateS'];
$dateE=$_POST['dateE'];
$colname_RsR = "repairs.RepairDate BETWEEN '$dateS' AND '$dateE' ";
}else if (($_POST['OfficerId']!="")) {
$colname_RsR = "repairs.OfficerId = ".$_POST['OfficerId'];
}else{
$colname_RsR = "1=1";
}
mysql_select_db($database_service, $service);
$query_RsRe = "SELECT repairs.RepairId, room.RoomName, equipment.EquipmentName, officer.OfficerName, repairs.RepairDate, repairs.Note, sympoms.SympomsName
FROM repairs LEFT OUTER JOIN room ON repairs.RoomId = room.RoomId LEFT OUTER JOIN equipment ON repairs.EquipmentId = equipment.EquipmentId LEFT OUTER JOIN officer ON repairs.OfficerId = officer.OfficerId LEFT OUTER JOIN sympoms ON repairs.SymptomsId = sympoms.SymptomsId
WHERE $colname_RsR GROUP BY repairs.RepairId DESC";
$query_limit_RsRe = sprintf("%s LIMIT %d, %d", $query_RsRe, $startRow_RsRe, $maxRows_RsRe);
$RsRe = mysql_query($query_limit_RsRe, $service) or die(mysql_error());
?>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td colspan="7" valign="bottom">
<form name="form1" id="form1" method="post" action="">
วันที่
<input name="dateS"id="dateS" type="text" value="" onclick="showCalendar('dateS','YYYY-MM-DD')" size="6" >
- <input name="dateE" id="dateE" type="text" value="" onclick="showCalendar('dateE','YYYY-MM-DD')" size="6" />
<select name="OfficerId">
<option value="">--เจ้าหน้าที่--</option>
<?php
do {
?>
<option value="<?php echo $row_RsOff['OfficerId']?>"><?php echo $row_RsOff['OfficerName']?></option>
<?php
} while ($row_RsOff = mysql_fetch_assoc($RsOff));
$rows = mysql_num_rows($RsOff);
if($rows > 0) {
mysql_data_seek($RsOff, 0);
$row_RsOff = mysql_fetch_assoc($RsOff);
}
?>
</select>
<select name="Eq" id="Eq">
<option value="">--อุปกรณ์--</option>
<?php
do {
?>
<option value="<?php echo $row_RsEq['EquipmentId']?>"><?php echo $row_RsEq['EquipmentName']?></option>
<?php
} while ($row_RsEq = mysql_fetch_assoc($RsEq));
$rows = mysql_num_rows($RsEq);
if($rows > 0) {
mysql_data_seek($RsEq, 0);
$row_RsEq = mysql_fetch_assoc($RsEq);
}
?>
</select>
<input type="submit" value="ค้นหา">
</form>
</td>
<td colspan="2" align="right">
<a href="print_re.php?id=<?=$colname_RsR?>" >พิมพ์รายงาน</a><a href="repairs_form.php">เพิ่มข้อมูล</a></td>
</tr>
<tr>
<td width="20" align="center" class="tdhead">ที่</td>
<td align="center" class="tdhead">ห้อง</</td>
<td align="center" class="tdhead">อุปกรณ์</td>
<td align="center" class="tdhead">เจ้าหน้าที่</td>
<td align="center" class="tdhead">วันที่แจ้ง</td>
<td align="center" class="tdhead">อาการเสีย</td>
<td align="center" class="tdhead">หมายเหตุ</td>
<td width="60" align="center" class="tdhead">จัดการ</td>
</tr>
<?php
$i=$pageNum_RsRe*$maxRows_RsRe+1 ;
do {
if($totalRows_RsRe !="0"){
?>
<tr>
<td class="tdgrid">
<? echo $i++;?>
</td>
<td class="tdgrid"><?php echo $row_RsRe['RoomName']; ?></td>
<td class="tdgrid" ><?php echo $row_RsRe['EquipmentName']; ?></td>
<td class="tdgrid"><?php echo $row_RsRe['OfficerName']; ?></td>
<td style="border-bottom: #CCC 1px dotted; text-align: center;">
<? echo ThShortdate($row_RsRe['RepairDate']);?>
</td>
<td class="tdgrid"><?php echo $row_RsRe['SympomsName']; ?></td>
<td class="tdgrid"><?php echo $row_RsRe['Note']; ?></td>
<td align="center" style="border-bottom:#CCC 1px dotted;">
<a href="repairs_edit.php?Id=<?php echo $row_RsRe['RepairId']; ?>"><img src="img/icon_edit.png" width="20" height="20" alt="แก้ไข" /></a> <a href="repairs_del.php?Id=<?php echo $row_RsRe['RepairId']; ?>" onclick="return confirm('ยืนยันการลบข้อมูล?')"><img src="img/icon_delete.png" width="20" height="20" alt="ลบ" /></a> </td>
</tr>
<?php }} while ($row_RsRe = mysql_fetch_assoc($RsRe));
?>
</table>
<table width="100%" border="0">
<tr>
<td><table border="0">
<tr>
<td><?php if ($pageNum_RsRe > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_RsRe=%d%s", $currentPage, 0, $queryString_RsRe); ?>"><img src="First.gif" /></a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_RsRe > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_RsRe=%d%s", $currentPage, max(0, $pageNum_RsRe - 1), $queryString_RsRe); ?>"><img src="Previous.gif" /></a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_RsRe < $totalPages_RsRe) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_RsRe=%d%s", $currentPage, min($totalPages_RsRe, $pageNum_RsRe + 1), $queryString_RsRe); ?>"><img src="Next.gif" /></a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_RsRe < $totalPages_RsRe) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_RsRe=%d%s", $currentPage, $totalPages_RsRe, $queryString_RsRe); ?>"><img src="Last.gif" /></a>
<?php } // Show if not last page ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="7">Total <?php echo $totalRows_RsRe ?> Records </td>
<td align="right">
</td>
</tr>
</table>
หน้าที่รับข้อมูลมา
Code (PHP)
<?php require_once('Connections/service.php'); ?>
<?php require_once('function.php'); ?>
<?php require_once('function.inc.php');?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$id_row=$_GET['id'];
//echo "$id_row<br><br>";
mysql_select_db($database_service, $service);
$query_RsRe = "SELECT repairs.RepairId, room.RoomName, equipment.EquipmentName, officer.OfficerName, repairs.RepairDate, repairs.Note, sympoms.SympomsName
FROM repairs LEFT OUTER JOIN room ON repairs.RoomId = room.RoomId LEFT OUTER JOIN equipment ON repairs.EquipmentId = equipment.EquipmentId LEFT OUTER JOIN officer ON repairs.OfficerId = officer.OfficerId LEFT OUTER JOIN sympoms ON repairs.SymptomsId = sympoms.SymptomsId
WHERE $id_row GROUP BY repairs.RepairId ASC";
$RsRe = mysql_query($query_RsRe) or die(mysql_error() . "<br /><br>" . $query_RsRe);
$row_RsRe = mysql_fetch_assoc($RsRe);
$totalRows_RsRe = mysql_num_rows($RsRe);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="style-print.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6" align="center"><h2>รายงานบันทึกการซ่อมบำรุง</h2><br />
</td>
</tr>
<tr>
<? $ct=" ".ThaiShortDateTime(date("Y-m-d")).date(" H:i:s")." น.";?>
<td colspan="6" align="right">วันที่สั่งพิมพ์ : <? echo $ct?>
</td>
</tr>
<tr align="center">
<td width="60" class="tdhead">ห้อง</td>
<td class="tdhead">อุปกรณ์</td>
<td class="tdhead">เจ้าหน้าที่</td>
<td class="tdhead">วันที่</td>
<td class="tdhead">อาการเสีย</td>
<td class="tdhead">หมายเหตุ</td>
</tr>
<?php do { ?>
<tr>
<td align="center" class="tdgrid" ><?php echo $row_RsRe['RoomName']; ?></td>
<td class="tdgrid" ><?php echo $row_RsRe['EquipmentName']; ?></td>
<td class="tdgrid"><?php echo $row_RsRe['OfficerName']; ?></td>
<td style="text-align:center;border-bottom:#CCC 1px dotted;"><?php echo ThShortdate($row_RsRe['RepairDate']); ?></td>
<td class="tdgrid"><?php echo $row_RsRe['SympomsName']; ?></td>
<td align="center" style="border-bottom:#CCC 1px dotted;"> <?php echo $row_RsRe['Note']; ?></td>
</tr>
<?php } while ($row_RsRe = mysql_fetch_assoc($RsRe)); ?>
</table>
<br /><br /><center><input type="button" id="print" name="print" value="พิมพ์หน้านี้" onClick="javascript:window.print()"/> <input type="button" id="print" name="print" value="ปิดหน้านี้" onClick="javascript:window.close()"/></center>
</body>
</html>
<?php
mysql_free_result($RsRe);
?>
ผมส่งค่ามาหน้านี้ ค่าที่ส่งมาตามรูปเลย ครับสงสัยว่า ผมส่ง
repairs.RepairDate BETWEEN '2012-11-01' AND '2012-11-30'
ผลที่ได้
repairs.RepairDate BETWEEN \'2012-11-01\' AND \'2012-11-30\'
แล้วทำให้เกิด Error
รบกวนผู้รู้หน่อยครับ ขอบคุณครับ
Tag : PHP, HTML/CSS, CakePHP, Device (Mobile), Android, JAVA
|
ประวัติการแก้ไข 2012-11-13 16:32:17
|
|
|
|
|
Date :
2012-11-13 16:07:15 |
By :
amonlove |
View :
818 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ต้องเอาโค้ดตัวเต็มมาดูครับ
|
|
|
|
|
Date :
2012-11-13 16:22:40 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไมถึงมี \ โผล่มาได้ล่ะครับ ผมยังหาจุดที่ผิดไม่ได้เลย หรือเป็นเพราะ sprintf งงจริงๆ
\'2012-11-01\'
|
|
|
|
|
Date :
2012-11-13 17:10:01 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สงสัยไปเข้า function mysql_real_escape_string() ตั้ง value ทั้งชุดแน่เลยครับ
|
|
|
|
|
Date :
2012-11-14 09:13:08 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|