|
|
|
ช่วยด้วยครับ ค้นหาแบบแบ่งหน้าพอคลิ๊กหน้าถัดไปมันดันส่งค่าเลขหน้าเข้ากล่องค้นหา ทำให้ข้อมูลไม่โชว์ มีรูปให้ดู |
|
|
|
|
|
|
|
ปัญหามันอยู่ตอนที่คลิ๊กหน้าถัดไปอ่ะครับ พอคลิ๊กแล้วมันส่งค่าเลขหน้าไปไว้ใน กล่องค้นหาด้วย ผมหาทางแก้แล้วแต่ไม่เจอสักที
รบกวนผู้รู้ช่วยผมทีนะครับ
หน้าแรกที่ค้นหา
หน้าต่อไป
Code (PHP)
<?php // code แบ่งหน้า
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 = 5;
$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 >1)
{
$this->return .= ($this->current_page != 1 And $this->items_total >= 1) ? "<a class=\"paginate\" href=\"".$this->url_next."1\">First Page</a> ":"<span class=\"inactive\" href=\"#\">« First Page</span> ";
$this->return .= ($this->current_page != 1 And $this->items_total >= 1) ? "<a class=\"paginate\" href=\"".$this->url_next.$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 >= 1) And ($_GET['Page'] != 'All')) ? "<a class=\"paginate\" href=\"".$this->url_next.$next_page."\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 1) And ($_GET['Page'] != 'All')) ? "<a class=\"paginate\" href=\"".$this->url_next.$this->num_pages."\">Last Page</a\n":"<span class=\"inactive\" href=\"#\">» Last Page</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;
}
} // end code แบ่งหน้า
?>
Code (PHP)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link rel="stylesheet" type="text/css" href="css/pup.css">
<link rel="stylesheet" type="text/css" href="css/reset.css">
<style type="text/css">
body {
background-image: url(Image/12351.jpg);
}
</style>
</head>
<style type="text/css">
<!--
.paginate {
font-family: Verdana, Geneva, sans-serif;
font-size: .30em;
}
a.paginate {
border: 1px solid #CCC;
padding: 2px 6px 2px 6px;
text-decoration: none;
color: #333;
}
h2 {
font-size: 12pt;
color: #333;
}
h2 {
line-height: 1.2em;
letter-spacing:-1px;
margin: 0;
padding: 0;
text-align: left;
}
a.paginate:hover {
background-color: #CCC;
color: #FFF;
text-decoration: underline;
}
a.current {
border: 1px solid #999;
font: bold .30em Verdana, Geneva, sans-serif;
padding: 2px 6px 2px 6px;
cursor: default;
background:#CCC;
color: #FFF;
text-decoration: none;
}
span.inactive {
border: 1px solid #999;
font-family: Verdana, Geneva, sans-serif;
font-size: .7em;
padding: 2px 6px 2px 6px;
color: #999;
cursor: default;
}
-->
</style>
<body>
<div id="wrapper">
<div id="header"></div>
<?PHP include("t_in.php"); ?>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1000" bgcolor="#228B22" style="font-family:'Arial Black', Gadget, sans-serif"><blockquote>
<strong><font color="#FFFFFF" size="5" style="text-shadow:3px 4px 5px #666;">Search</font></strong></blockquote>
</td>
</tr>
</table>
<br />
<form id="search" name="search" method="GET" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="1000" align="center" cellpadding="4" cellspacing="3" style="font-family:Verdana, Geneva, sans-serif">
<tr>
<td align="center" bgcolor="#96DBF5"><strong>Select ::
<select name="s_search" id="s_search" value="<?=$_GET["s_search"];?>">
<option>- Select -</option>
<option value="jobid" <?if($_GET["s_search"]=="jobid"){echo"selected";}?>>Job No</option>
<option value="Consignee_name" <?if($_GET["s_search"]=="Consignee_name"){echo"selected";}?>>Consignee Name</option>
<option value="Type" <?if($_GET["s_search"]=="Type"){echo"selected";}?>>Type</option>
<option value="At" <?if($_GET["s_search"]=="At"){echo"selected";}?>>By</option>
<option value="work_status" <?if($_GET["s_search"]=="work_status"){echo"selected";}?>>Work Status</option>
</select>
</strong><strong>Keyword ::
<input type="text" name="k_search" id="k_search" value="<?=$_GET["k_search"];?>"/>
</strong> <input type="submit" name="Search" id="Search" value="Search" /></td>
</tr>
</table>
</form>
<?
if($_GET["k_search"] != "")
{
// Search
if($_GET["s_search"] == 'jobid')
{
if($_GET["k_search"] != "")
{
$strSQL = "
SELECT jobid,Type,Consignee_name,Type,At,Vessel,Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_sea
WHERE (jobid LIKE '%".$_GET["k_search"]."' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_air
WHERE (jobid LIKE '%".$_GET["k_search"]."' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_truck
WHERE (jobid LIKE '%".$_GET["k_search"]."' )
"; // End Search :: jobid
}
}else if($_GET["s_search"] == 'Consignee_name')
{
if($_GET["k_search"] != "")
{
$strSQL = "
SELECT jobid,Type,Consignee_name,Type,At,Vessel,Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_sea
WHERE (Consignee_name LIKE '%".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_air
WHERE (Consignee_name LIKE '%".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_truck
WHERE (Consignee_name LIKE '%".$_GET["k_search"]."%' )
"; // End Search :: Consignee_name
}
}else if($_GET["s_search"] == 'Type')
{
if($_GET["k_search"] != "")
{
$strSQL = "
SELECT jobid,Type,Consignee_name,Type,At,Vessel,Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_sea
WHERE (Type LIKE '".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_air
WHERE (Type LIKE '".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_truck
WHERE (Type LIKE '".$_GET["k_search"]."%' )
"; // End Search :: Type
}
}else if ($_GET["s_search"] == 'At'){
if($_GET["k_search"] != "")
{
$strSQL = "
SELECT jobid,Type,Consignee_name,Type,At,Vessel,Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_sea
WHERE (At LIKE '".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_air
WHERE (At LIKE '".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_truck
WHERE (At LIKE '".$_GET["k_search"]."%' )
"; // End Search :: By
}
}else if ($_GET["s_search"] == 'work_status'){
if($_GET["k_search"] != "")
{
$strSQL = "
SELECT jobid,Type,Consignee_name,Type,At,Vessel,Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_sea
WHERE (work_status LIKE '".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_air
WHERE (work_status LIKE '".$_GET["k_search"]."%' )
UNION
SELECT jobid,Type,Consignee_name,Type,At,'Vessel',Port,Bl_id,Inv_id,Cont20,Cont40,
Package,Gross_weight,Description,Attach1,Attach2,work_status,date FROM service_truck
WHERE (work_status LIKE '".$_GET["k_search"]."%' )
"; // End Search :: work_status
}
}
$objQuery = mysql_query($strSQL)or die (mysql_error());
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 10; // 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;
}
$strSQL .=" order by jobid LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="1000" align="center" cellpadding="4" cellspacing="3" style="font-family:Verdana, Geneva, sans-serif">
<tr>
<th width="180" bgcolor="#6699FF"> <div align="center">Date</div></th>
<th width="80" bgcolor="#6699FF"> <div align="center">Job No </div></th>
<th bgcolor="#6699FF"> <div align="center">Consignee Name </div></th>
<th width="80" bgcolor="#6699FF"> <div align="center">Type </div></th>
<th width="80" bgcolor="#6699FF"> <div align="center">By </div></th>
<th width="80" bgcolor="#6699FF"> <div align="center">Status</div></th>
<th width="80" bgcolor="#6699FF"> <div align="center">show</div></th>
</tr>
<?php
$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++; // คำสั่งวนลูบ ให้ตารางที่ดึงออกมา ใช้สีสลับกัน
if($i%2==0)
{
$bg = "#AFEEEE";
}
else
{
$bg = "#E0FFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center" style="font-size:14px"><?=$objResult["date"];?></div></td>
<td><div align="center" style="font-size:14px"><?=$objResult["jobid"];?></div></td>
<td style="font-size:14px"><div><?=$objResult["Consignee_name"];?></div></td>
<td style="font-size:14px"><div align="center"><?=$objResult["Type"];?></div></td>
<td style="font-size:14px"><div align="left"><?=$objResult["At"];?></div></td>
<td style="font-size:14px"><div align="center"><?php $work_status= $objResult["work_status"]; // เช็คสถานะ ถ้าเป็น New ให้แสดงเป็นรููป ถ้าไม่ใช่ให้แสดงสถานะนั้นๆ
if($work_status == "New"){
echo "<a href='form_emp.php?jobid=".$objResult["jobid"]."'>
<img src='Image/t_new.ico', width='40', height='40' ></a>";
}else{
echo $objResult["work_status"];
}?>
</div></td>
<td><div align="center"><a href="form_re_show.php?jobid=<?php echo $objResult["jobid"];?>"><img src='Image/t_show.ico' width="40" height="40"></a></div></td>
</tr>
<?
}
?>
</table>
<font style="font-size:12px"> 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["SCRIPT_NAME"]."?QueryString=value&Page=$Next_Page&s_search=$_GET[s_search]&k_search=$_GET[k_search]";
//$_SERVER["PHP_SELF"]."?QueryString=value&Page=";
$pages->paginate();
echo $pages->display_pages()
?>
<?
mysql_close();
?>
</td>
</tr>
</table>
<br /><br /><br />
<div id="footer"></div>
</div>
</body>
Tag : PHP, MySQL, HTML/CSS, JavaScript
|
|
|
|
|
|
Date :
2013-03-27 14:44:40 |
By :
Flintstone |
View :
800 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$pages->url_next = $_SERVER["SCRIPT_NAME"]."?QueryString=value&Page=$Next_Page&s_search=$_GET[s_search]&k_search=$_GET[k_search]";
ลองย้ายตัวแปร Page= ไปไว้หลังสุดครับ
|
|
|
|
|
Date :
2013-03-27 15:17:35 |
By :
Necrotorture |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$pages->url_next = $_SERVER["SCRIPT_NAME"]."?QueryString=$Next_Page&s_search=$_GET[s_search]&k_search=$_GET[k_search]&Page=";
|
ประวัติการแก้ไข 2013-03-27 17:24:19
|
|
|
|
Date :
2013-03-27 17:23:01 |
By :
nirunsu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ ขอบคุณมากๆครับ คุณ ReBirTh และ คุณDeaw
|
|
|
|
|
Date :
2013-03-27 20:56:46 |
By :
Flintstone |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|