|
|
|
ช่วยดูให้หน่อยครับ คือเกี่ยวกับ search และ sort ครับ ต้องการให้มันคงค่าที่ดำเนินการอยู่ครับ |
|
|
|
|
|
|
|
โค้ด
Code (PHP)
<?
class Paginator{
var $items_per_page;var $items_total;var $current_page;var $num_pages;var $mid_range;var $low;var $high;
var $limit;var $return;var $default_ipp;var $querystring;var $url_next;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = $this->default_ipp;
$this->url_next = $this->url_next;
}
function paginate()
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"".$this->url_next.$this->$prev_page."\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['Page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"".$this->url_next.$i."\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['Page'] != 'All')) ? "<a class=\"paginate\" href=\"".$this->url_next.$next_page."\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"".$this->url_next.$i."\">$i</a> ";
}
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_pages()
{
return $this->return;
}
}
?>
<?
session_start();
if ($_SESSION['ADMINID'] == "") { //ถ้าตัวแปรเป็นค่า ว่าง
header("Location:login.php"); //ให้ไปหน้า login
}
include("../connect.php");
$strSQL = "SELECT * FROM members WHERE UserID = '".$_SESSION['ADMINID']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
mysql_query("SET character_set_results=UTF8");
mysql_query("SET character_set_client=UTF8");
mysql_query("SET character_set_connection=UTF8");
?>
<!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>: : รายการใบสั่งงาน : :</title>
<link rel="stylesheet" type="text/css" href="../Scripts/epoch_styles.css"/>
<script type="text/javascript" src="../Scripts/epoch_classes.js">//***Calendar****//</script>
<script type="text/javascript">
var calendar;
window.onload = function() {
calendar = new Epoch('cal2','popup',document.getElementById('calendar_container'),false);
};
</script>
<script type="text/javascript">
function MM_openBrWindow(URL, N, W, H, S) { // name, width, height, scrollbars
var winleft = (screen.width - W) / 2;
var winup = (screen.height - H) / 2;
winProp = 'width='+W+',height='+H+',left='+winleft+',top=' +winup+',scrollbars='+S+',resizable' + ',status=no'
Win = window.open(URL, N, winProp)
}
</script>
<style type="text/css">
<!--
.paginate {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
}
a.paginate {
border: 1px solid #000080;
padding: 2px 6px 2px 6px;
text-decoration: none;
color: #000080;
}
h2 {
font-size: 12pt;
color: #003366;
}
h2 {
line-height: 1.2em;
letter-spacing:-1px;
margin: 0;
padding: 0;
text-align: left;
}
a.paginate:hover {
background-color: #000080;
color: #FFF;
text-decoration: underline;
}
a.current {
border: 1px solid #000080;
font: bold .7em Arial,Helvetica,sans-serif;
padding: 2px 6px 2px 6px;
cursor: default;
background:#000080;
color: #FFF;
text-decoration: none;
}
span.inactive {
border: 1px solid #999;
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
padding: 2px 6px 2px 6px;
color: #999;
cursor: default;
}
-->
</style>
<style type="text/css">
<!--
.style3 {font-size: 12px; color: #FFFFFF; }
a:link {
color: #0033FF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #0033FF;
}
a:hover {
text-decoration: none;
color: #00FF00;
}
a:active {
text-decoration: none;
color: #FF0000;
}
.style6 {font-size: 12px; font-weight: bold; color: #FFFFFF; }
body {
background-repeat: no-repeat;
}
.style12 {color: #000000}
.style13 {font-size: 12px; color: #000000; }
.style19 {font-size: 13px}
.style20 {font-size: 13px; font-weight: bold; }
.style22 {color: #999999}
.style23 {font-size: 12px}
-->
</style>
</head>
<body background="../image/(246).jpg" bgproperties="fixed">
<script language="javascript">
function fncSubmit()
{
if(document.frmSearch.ddlSelect.value == "select")
{
alert('กรุณาเลือกสิ่งที่ต้องการค้นหา');
document.frmSearch.ddlSelect.focus();
return false;
}
document.frmSearch.submit();
}
</script>
</p>
<table border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FF9900">
<tr>
<th colspan="6" align="left">
<form name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>" OnSubmit="return fncSubmit();">
<table width="772" border="0" cellpadding="3" cellspacing="1">
<tr>
<th width="577" align="left"><p><span class="style6">ค้นหาโดย</span>
<select name="ddlSelect" id="ddlSelect" style="width:100px">
<option value="select" selected="selected">- Select -</option>
<option value="worker1"<?if($_POST["ddlSelect"]=="worker1"){echo"selected";}?>>ชื่อผู้ปฏิบัติงาน</option>
<option value="date"<?if($_POST["ddlSelect"]=="date"){echo"selected";}?>>วันที่ดำเนินการ</option>
<option value="status" <?if($_POST["ddlSelect"]=="status"){echo"selected";}?>>ผลการปฏิบัติงาน</option>
<option value="IDwork" <?if($_POST["ddlSelect"]=="IDwork"){echo"selected";}?>>เลขที่ใบสั่งงาน</option>
</select>
<span class="style6">สิ่งที่ต้องการค้นหา</span>
<input name="txtKeyword" type="text" style="width:100px" id="calendar_container" value="<?=$_POST["txtKeyword"];?>" />
<input type="submit" value="Search">
<span class="style13 style12">**ถ้าไม่ต้องการเลือกวันที่ให้พิมพ์ข้อความลงในช่องได้เลย</span></th>
</tr>
</table>
</form></th>
<?
// Search
$workSQL = "SELECT * FROM workorder WHERE 1 ";
if ($_POST["ddlSelect"] != "" and $_POST["txtKeyword"] != '')
{
if($_POST["ddlSelect"] == "worker1")
{
$workSQL .= " AND (worker1 LIKE '%".$_POST["txtKeyword"]."%' or worker2 LIKE '%".$_POST["txtKeyword"]."%' or worker3 LIKE '%".$_POST["txtKeyword"]."%' or worker4 LIKE '%".$_POST["txtKeyword"]."%' )";
}
else
{
if($_POST["ddlSelect"]=="date"){
$workSQL .= " AND (date LIKE '".$_POST["txtKeyword"]."')";
}
else
{
if($_POST["ddlSelect"]=="status"){
$workSQL .= " AND (status LIKE '".$_POST["txtKeyword"]."')";
}
else
{
$workSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' )";
}
}
}
}
$workQuery = mysql_query($workSQL) or die ("Error Query [".$workSQL."]");
$Num_Rows = mysql_num_rows($workQuery);
$Per_Page = 50; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSort = $_GET["sort"];
if($strSort == "")
{
$strSort = "IDwork";
}
$strOrder = $_GET["order"];
if($strOrder == "")
{
$strOrder = "ASC";
}
$workSQL .=" order by ".$strSort." ".$strOrder." LIMIT $Page_Start , $Per_Page";
$workQuery = mysql_query($workSQL);
$strNewOrder = $strOrder == 'DESC' ? 'ASC' : 'DESC';
?>
<th align="right" valign="top"> </th>
<th colspan="3" align="right" valign="top" bgcolor="#FFFFFF"><span class="style6 style12"><span class="style22">ID</span> <?php echo $objResult["UserID"];?> <span class="style22">ชื่อ</span> <?php echo $objResult["fname"];?></span></th>
<th align="right" valign="top" bgcolor="#FFFFFF"><a href="../admin_page.php"><img src="../image/icon_house.gif" width="50" height="50" border="0" /></a></th>
</tr>
<tr bgcolor="#FFFFFF">
<th colspan="11"> </th>
</tr>
<tr>
<th bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=IDwork&order=<?=$strNewOrder?>" class="style23">เลขที่ใบสั่งงาน</a></th>
<th bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=work&order=<?=$strNewOrder?>" class="style23">งานที่มอบหมาย</a></th>
<th bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=date&order=<?=$strNewOrder?>" class="style23">วันที่ดำเนินการ</a></th>
<th bgcolor="#FFFFFF"><span class="style13">ผู้ปฏิบัติงาน</span></th>
<th bgcolor="#FFFFFF"><span class="style13">ผลการปฏิบัติงาน</span></th>
<th bgcolor="#FFFFFF"><a href="<?=$_SERVER["SCRIPT_NAME"];?>?sort=UserID&order=<?=$strNewOrder?>" class="style13">รหัสผู้บันทึก</a></th>
<th bgcolor="#FFFFFF"><span class="style13">ชื่อผู้บันทึก</span></th>
<th bgcolor="#FFFFFF" class="style3 style12 style23">แก้ไขล่าสุด</th>
<th bgcolor="#FFFFFF"><p class="style13">ผู้แก้ไข</p></th>
<th colspan="2" bgcolor="#FFFFFF"><span class="style23"></span></th>
</tr>
<?
while($workResult = mysql_fetch_array($workQuery))
{
$i++;
if($i%2==0){$bg = "#FFFFCC";}// ใส่สีในตารางแบบสลับสี ตั้งแต่ $i ถึง $bg
else{$bg = "#FFFFFF";}
?>
<tr valign="top" bgcolor="<?=$bg;?>">
<td align="center" valign="top" bgcolor="<?=$bg;?>"><span class="style19">
<?=$workResult["IDwork"];?>
</span> </td>
<td valign="top" bgcolor="<?=$bg;?>"> <span class="style19">
<?=$workResult["work"];?>
</span> </td>
<td align="center" valign="top" bgcolor="<?=$bg;?>"><span class="style19">
<?=$workResult["date"];?>
</span></td>
<td valign="top" bgcolor="<?=$bg;?>"><span class="style19">
<? if($workResult["worker1"] != '' ){echo $workResult["worker1"]."<br />";}?>
<? if($workResult["worker2"] != '' ){echo $workResult["worker2"]."<br />";}?>
<? if($workResult["worker3"] != '' ){echo $workResult["worker3"]."<br />";} ?>
<? if($workResult["worker4"] != '' ){echo $workResult["worker4"]."";} ?>
</span></td>
<td valign="top" bgcolor="<?=$bg;?>">
<span class="style19">
<?
if ($workResult["status"]=='เรียบร้อย'){
echo 'เรียบร้อย';}
else {
echo '<span><font color="#FF0000" style="size:14px"><b><u>ไม่เรียบร้อย</u></b></font></span></td>';}
?>
</span>
<td align="center" valign="top" bgcolor="<?=$bg;?>"><span class="style19">
<?=$workResult["UserID"];?>
</span></td>
<td valign="top" bgcolor="<?=$bg;?>"><span class="style19">
<?=$workResult["fname"];?>
</span></td>
<td align="center" bgcolor="#FFFFFF"><span class="style19">
<?=$workResult["date_up"];?>
</span></td>
<td valign="top" bgcolor="#FFFFFF"><span class="style19">
<?=$workResult["Update_by"];?>
</span></td>
<td valign="top" bgcolor="#FFFFFF"><a href="javascript:MM_openBrWindow('show_detail_workorder_ADMIN.php?IDwork=<?=$workResult["IDwork"];?>','detail','480','300','no')" class="style20">รายละเอียด</a></td>
<td align="center" valign="top" bgcolor="#FFFFFF"><span class="style20"><a href="Editwork_ADMIN.php?IDwork=<?=$workResult["IDwork"];?>"><img src="../image/edit_24.png" width="24" height="24" border="0" /></a> <a href="del.php?IDwork=<?=$workResult["IDwork"];?>"><img src="../image/del_24.png" width="24" height="24" border="0" /></a></span></td>
</tr>
<?
}
?>
</table>
<p align="center">Total
<?= $Num_Rows;?>
Record
<?
$pages = new Paginator;
$pages->items_total = $Num_Rows;
$pages->mid_range = 10;
$pages->current_page = $Page;
$pages->default_ipp = $Per_Page;
$pages->url_next = $_SERVER["PHP_SELF"]."?QueryString=value&Page=";
$pages->paginate();
echo $pages->display_pages()
?>
<?
mysql_close();
?>
</p>
<div align="left"></div>
</body>
</html>
คือพอเลือก search หรือ sort แล้วเปลี่ยนหน้าแสดงข้อมูล ค่าเหล่านั้นไม่เป็นไปตามที่ทำไว้ครับ มันคืนค่าหมือนเดมหมดเลย
จะแก้ยังไงครับ
อย่างถ้า serach อยู่ เมื่อจะดูหน้าถัดไป ข้อมูลก็ยังจะอยู่ในลักษณะ search อ่ะครับ
Tag : PHP, MySQL, JavaScript
|
|
|
|
|
|
Date :
2012-02-23 11:08:49 |
By :
akkaneetha |
View :
1073 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$pages->url_next = $_SERVER["PHP_SELF"]."?QueryString=value&Page=";
ส่งตัวแปร search ไปด้วยครับ
|
|
|
|
|
Date :
2012-02-23 11:31:02 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวน แก้โค้ดให้ได้มั้ยครับ ผมไม่เข้าใจตรงตัวแปร search ว่ามันคือตัวไหน แล้วจะต้องใส่อย่างไรครับ
|
|
|
|
|
Date :
2012-02-27 10:37:36 |
By :
akkaneetha |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือตอนที่คุณค้นหามันจะต้องมีค่าตัวแปร และตอนที่ไปหน่าอื่น ๆ คุรก็จะต้องส่งค่าตัวแปรไปด้วยครับ
|
|
|
|
|
Date :
2012-02-27 20:43:43 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|