ส่วนนี้ คือ ฟอร์มที่ใช้รับข้อมูลครับ
<form action="search_date.php" method="post" name="date">
Start Date<br/>
<input name="startdate" type="text" class="form-control" id="startdate" />
<br/>
End Date<br/>
<input name="enddate" type="text" class="form-control" id="enddate" /><br/>
<button name="btnSeacrch" type="submit" class="btn btn-warning" id="btnSeacrch"><i class="icon-search"></i> Search</button>
</form>
ส่วนนี้คือ code ครับ รบกวนผู้รู้แนะนำหน่อยครับ ปรับเปลี่ยน หรือ ผิดตรงไหน ช่วยทีครับ มือใหม่หัดแกะ php
ปล copy code เค้ามาอีกที
<?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;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$colname_Search = "-2";
if (isset($_POST['startdate'])) {
$colname_Search1 = $_POST['startdate'];
}
if (isset($_POST['enddate'])) {
$colname_Search2 = $_POST['enddate'];
}
mysql_select_db($database_IT, $IT);
$query_Search = sprintf("SELECT * FROM claim WHERE f_branchdate>=$colname_Search1 and f_branchdate<=$colname_Search2", GetSQLValueString("%" . $colname_Search1 . "%", "text")&& GetSQLValueString("%" . $colname_Search2 . "%", "text") );
$Search = mysql_query($query_Search, $IT) or die(mysql_error());
$row_Search = mysql_fetch_assoc($Search);
$totalRows_Search = mysql_num_rows($Search);
$queryString_Search = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Search") == false &&
stristr($param, "totalRows_Search") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Search = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Search = sprintf("&totalRows_Search=%d%s", $totalRows_Search, $queryString_Search);
?>
ขอความช่วย form ค้นหาข้อมูล แบบ เลือกช่วงวันที่เริ่มต้น - วันที่สิ้นสุด
<form action="search_date.php" method="post" name="date">
Start Date<br/>
<input name="startdate" type="text" class="form-control" id="startdate" />
<br/>
End Date<br/>
<input name="enddate" type="text" class="form-control" id="enddate" /><br/>
<button name="btnSeacrch" type="submit" class="btn btn-warning" id="btnSeacrch"><i class="icon-search"></i> Search</button>
</form>
ส่วนนี้คือ code ครับ รบกวนผู้รู้แนะนำหน่อยครับ ปรับเปลี่ยน หรือ ผิดตรงไหน ช่วยทีครับ มือใหม่หัดแกะ php
ปล copy code เค้ามาอีกที
<?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;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$colname_Search = "-2";
if (isset($_POST['startdate'])) {
$colname_Search1 = $_POST['startdate'];
}
if (isset($_POST['enddate'])) {
$colname_Search2 = $_POST['enddate'];
}
mysql_select_db($database_IT, $IT);
$query_Search = sprintf("SELECT * FROM claim WHERE f_branchdate>=$colname_Search1 and f_branchdate<=$colname_Search2", GetSQLValueString("%" . $colname_Search1 . "%", "text")&& GetSQLValueString("%" . $colname_Search2 . "%", "text") );
$Search = mysql_query($query_Search, $IT) or die(mysql_error());
$row_Search = mysql_fetch_assoc($Search);
$totalRows_Search = mysql_num_rows($Search);
$queryString_Search = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Search") == false &&
stristr($param, "totalRows_Search") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Search = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Search = sprintf("&totalRows_Search=%d%s", $totalRows_Search, $queryString_Search);
?>