|
|
|
เวลากดปุ่มค้นหาต้องดับเบิ้ลคลิกทำยังไงให้คลิกแค่ครั้งเดียว แล้วก็สามารถกด Enter เพื่อค้นหาได้ ต้องแก้ยังไงค่ะ |
|
|
|
|
|
|
|
ต้องเอาโค้ดมาดูครับ
|
|
|
|
|
Date :
2014-06-12 10:13:25 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('Connections/Connect_db.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;
}
}
$maxRows_search1 = 10;
$pageNum_search1 = 0;
if (isset($_GET['pageNum_search1'])) {
$pageNum_search1 = $_GET['pageNum_search1'];
}
$startRow_search1 = $pageNum_search1 * $maxRows_search1;
$colname_search1 = "-1";
if (isset($_POST['word'])) {
$colname_search1 = $_POST['word'];
}
mysql_select_db($database_Connect_db, $Connect_db);
$query_search1 = sprintf("SELECT * FROM tb_request WHERE Name LIKE %s ORDER BY id_req ASC", GetSQLValueString("%" . $colname_search1 . "%", "text"));
$query_limit_search1 = sprintf("%s LIMIT %d, %d", $query_search1, $startRow_search1, $maxRows_search1);
$search1 = mysql_query($query_limit_search1, $Connect_db) or die(mysql_error());
$row_search1 = mysql_fetch_assoc($search1);
if (isset($_GET['totalRows_search1'])) {
$totalRows_search1 = $_GET['totalRows_search1'];
} else {
$all_search1 = mysql_query($query_search1);
$totalRows_search1 = mysql_num_rows($all_search1);
}
$totalPages_search1 = ceil($totalRows_search1/$maxRows_search1)-1;
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php mysql_query("SET NAMES UTF8");?>
<table width="200" border="0">
<tr>
<td><a href="frm_homepag.php">
<input type="image" name="imageField9" id="imageField11" src="001_20.gif" />
กลับสู่หน้าหลัก</a> <input type="image" name="imageField" id="imageField" src="Head.jpg" /></td>
</tr>
<tr>
<td height="79" align="center"><form id="form2" name="form2" method="post" action="">
<table width="314" border="0">
<tr>
<td width="48" height="73"><input type="image" name="imageField2" id="imageField2" src="48px-Crystal_Clear_app_xmag.png" /></td>
<td width="144"><input type="text" name="word" id="word" /></td>
<td width="108"><input type="submit" name="bntsearch" id="bntsearch" value="ค้นหา" /></td>
</tr>
</table>
<input type="submit" name="button" id="button" value="Submit" />
</form></td>
</tr>
<tr>
<td align="center"><p> </p>
<p>ผลการค้นหา </p>
<p>
<input type="image" name="imageField3" id="imageField3" src="48px-Crystal_Clear_app_kfind.png" />
</p>
<table border="1">
<tr>
<td align="center">ชื่อเจ้าของเครื่อง </td>
<td align="center">วันที่แจ้ง </td>
<td align="center">ชื่อผู้แจ้ง </td>
<td align="center">แผนก</td>
<td align="center">กลุ่มธุรกิจ</td>
<td align="center">อุปกรณ์ที่ขอเพิ่ม</td>
<td align="center">รายละเอียด</td>
</tr>
<?php do { ?>
<tr>
<td align="center">-<?php echo $row_search1['ComputerName']; ?></td>
<td align="center">-<?php echo $row_search1['datetime']; ?></td>
<td align="center">-<?php echo $row_search1['Name']; ?></td>
<td align="center">-<?php echo $row_search1['division']; ?></td>
<td align="center">-<?php echo $row_search1['group']; ?></td>
<td align="center">-<?php echo $row_search1['requests']; ?></td>
<td align="center">-<?php echo $row_search1['details']; ?></td>
</tr>
<?php } while ($row_search1 = mysql_fetch_assoc($search1)); ?>
</table>
<p> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($search1);
?>
|
ประวัติการแก้ไข 2014-06-12 10:19:04
|
|
|
|
Date :
2014-06-12 10:17:57 |
By :
Loogsorn22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเปลี่ยนจาก post เป็น get เพื่อดูว่าการกดปุ่ม submit ครั้ง พารามิเตอร์หรือตัวแปรที่ได้ถูกต้องมั๊ย
<form id="form2" name="form2" method="post" action="">
<form id="form2" name="form2" method="get" action="">
|
|
|
|
|
Date :
2014-06-12 10:49:26 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quote:โอเคครับ งั้นช่วยลองโค้ดชุดนี้ด้วย
และสังเกตการกดปุ่มค้นหาครั้งแรก มองตรงช่อง url และคัดลอกมาให้ดูด้วย
Code (PHP)
<?php require_once('Connections/Connect_db.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;
}
}
$maxRows_search1 = 10;
$pageNum_search1 = 0;
if (isset($_GET['pageNum_search1'])) {
$pageNum_search1 = $_GET['pageNum_search1'];
}
$startRow_search1 = $pageNum_search1 * $maxRows_search1;
$colname_search1 = "-1";
if (isset($_GET['word'])) {
$colname_search1 = $_GET['word'];
}
mysql_select_db($database_Connect_db, $Connect_db);
$query_search1 = sprintf("SELECT * FROM tb_request WHERE Name LIKE %s ORDER BY id_req ASC", GetSQLValueString("%" . $colname_search1 . "%", "text"));
$query_limit_search1 = sprintf("%s LIMIT %d, %d", $query_search1, $startRow_search1, $maxRows_search1);
$search1 = mysql_query($query_limit_search1, $Connect_db) or die(mysql_error());
//$row_search1 = mysql_fetch_assoc($search1);
if (isset($_GET['totalRows_search1'])) {
$totalRows_search1 = $_GET['totalRows_search1'];
} else {
$all_search1 = mysql_query($query_search1);
$totalRows_search1 = mysql_num_rows($all_search1);
}
$totalPages_search1 = ceil($totalRows_search1/$maxRows_search1)-1;
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php mysql_query("SET NAMES UTF8");?>
<table width="200" border="0">
<tr>
<td><a href="frm_homepag.php">
<input type="image" name="imageField9" id="imageField11" src="001_20.gif" />
กลับสู่หน้าหลัก</a> <input type="image" name="imageField" id="imageField" src="Head.jpg" /></td>
</tr>
<tr>
<td height="79" align="center">
<form id="form2" name="form2" method="get" action="">
<table width="314" border="0">
<tr>
<td width="48" height="73"><input type="image" name="imageField2" id="imageField2" src="48px-Crystal_Clear_app_xmag.png" /></td>
<td width="144"><input type="text" name="word" id="word" /></td>
<td width="108"><input type="submit" name="bntsearch" id="bntsearch" value="ค้นหา" /></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td align="center"><p> </p>
<p>ผลการค้นหา </p>
<p>
<input type="image" name="imageField3" id="imageField3" src="48px-Crystal_Clear_app_kfind.png" />
</p>
<table border="1">
<tr>
<td align="center">ชื่อเจ้าของเครื่อง </td>
<td align="center">วันที่แจ้ง </td>
<td align="center">ชื่อผู้แจ้ง </td>
<td align="center">แผนก</td>
<td align="center">กลุ่มธุรกิจ</td>
<td align="center">อุปกรณ์ที่ขอเพิ่ม</td>
<td align="center">รายละเอียด</td>
</tr>
<?php do { ?>
<tr>
<td align="center">-<?php echo $row_search1['ComputerName']; ?></td>
<td align="center">-<?php echo $row_search1['datetime']; ?></td>
<td align="center">-<?php echo $row_search1['Name']; ?></td>
<td align="center">-<?php echo $row_search1['division']; ?></td>
<td align="center">-<?php echo $row_search1['group']; ?></td>
<td align="center">-<?php echo $row_search1['requests']; ?></td>
<td align="center">-<?php echo $row_search1['details']; ?></td>
</tr>
<?php } while ($row_search1 = mysql_fetch_assoc($search1)); ?>
</table>
<p> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
//mysql_free_result($search1);
?>
<?php
//mysql_free_result($search1);
?>
|
ประวัติการแก้ไข 2014-06-12 11:21:47
|
|
|
|
Date :
2014-06-12 11:18:39 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-06-12 11:48:43 |
By :
Loogsorn22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผลลัพธ์ที่ได้มาจากโค้ดที่ผมแก้ให้หรือเปล่าครับ No.9
เปลี่ยนจาก $_POST เป็น $_GET
$colname_search1 = "-1";
if (isset($_GET['word'])) {
$colname_search1 = $_GET['word'];
}
|
|
|
|
|
Date :
2014-06-12 11:52:26 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วคำสั่ง sql ที่แสดงออกมาหน้าจอ จากบรรทัดนี้ล่ะครับ
echo $query_limit_search1
ขอดูหน่อยครับ
|
|
|
|
|
Date :
2014-06-12 14:56:29 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT * FROM tb_request WHERE Name LIKE '%%' ORDER BY id_req ASC LIMIT 0, 10
|
|
|
|
|
Date :
2014-06-12 14:58:43 |
By :
Loogsorn22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|