|
|
|
การใส่ code แบ่งหน้า ร่วมกับ jquery ส่งค่า post ในหน้าเดียวกัน อย่างไรดีครับ |
|
|
|
|
|
|
|
ปรึกษาครับผมอยากใส่ตัวแบ่งหน้า รวมกับโค๊ด ส่งค่า post กลับหน้าเดิม ต้องปรับแก้ตรงไหนครับ
หน้า view.php
Code (PHP)
<!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>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#button').click(function(){
var txt=$('#form1').serialize(); // ใช้ serialize() รวมเอา ค่าทั้งหมดที่อยู่ใน form
$.ajax({
type: 'POST',
url: "view2.php",
data: txt,
success: function(data){
$('#result').html( data );
}
});
})
});
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6" align="center"><h2>ค้นหา</h2></td>
</tr>
<tr>
<td width="18%"> ปี
<select name="year" class="textbox" id="year" >
<?php $objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("project");
mysql_query("SET NAMES UTF8");
$selectYear = "SELECT a_year FROM topic group by a_year order by a_year DESC";
$sqlYear = mysql_query($selectYear) or die ("Error Query [".$selectYear."]");?>
<option value="0">ทั้งหมด</option>
<?php
while($year = mysql_fetch_array($sqlYear))
{ ?>
<option value="<?php echo $year["a_year"]?>"><?php echo $year["a_year"]; ?></option>
<?php } ?>
</select></td>
<td><label>
<input type="radio" name="status" value="1" id="status_check_0" />
ใช้งาน</label></td>
<td><label>
<input type="radio" name="status" value="0" id="status_check_1" />
ยกเลิก</label></td>
<td><label>
<input name="status" type="radio" id="status_check_2" value="2" checked="checked" />
ทั้งหมด</label></td>
<td width="24%"><input name="search" type="text" class="textboxinput" id="search" /></td>
<td width="25%"><input name="button" type="button" class="button_text" id="button" value="ค้นหา"/>
<input name="button2" type="reset" class="button_text2" id="button2" value="ล้างข้อมูล"/></td>
</tr>
</table>
</form>
<br />
<span id="result"></span>
</body>
</html>
หน้า view2.php
Code (PHP)
<!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>
<style>
ul.pagination {
display: inline-block;
padding: 0;
margin: 0;
}
ul.pagination li {display: inline;}
ul.pagination li a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.pagination li:first-child a {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.pagination li:last-child a {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
ul.pagination li a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
ul.pagination li a:hover:not(.active) {background-color: #ddd;}
</style>
</head>
<body>
<?php
$year = $_POST["year"];
$search = $_POST["search"];
$status = $_POST["status"];
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("project");
mysql_query("SET NAMES UTF8");
if($year==0 && $status==1 && $search==0)
{
$strSQL="SELECT * FROM topic WHERE a_status=1 ";
}
if($year==0 && $status==2 && $search==0)
{
$strSQL="SELECT * FROM topic ";
}
if($year==0 && $status==0 && $search==0)
{
$strSQL="SELECT * FROM topic WHERE a_status=0 ";
}
if($year==0 && $status==1 && $search!="")
{
$strSQL="SELECT * FROM topic WHERE a_name LIKE '%".$search."%' AND a_status=1 ";
}
if($year==0 && $status==2 && $search!="")
{
$strSQL="SELECT * FROM topic WHERE a_name LIKE '%".$search."%' ";
}
//
if($year!=0 && $status==1 && $search==0)
{
$strSQL="SELECT * FROM topic WHERE a_status=1 AND a_year =$year ";
}
if($year!=0 && $status==2 && $search==0)
{
$strSQL="SELECT * FROM topic WHERE a_year =$year";
}
if($year!=0 && $status==0 && $search==0)
{
$strSQL="SELECT * FROM topic WHERE a_status=0 AND a_year =$year";
}
if($year!=0 && $status==1 && $search!="")
{
$strSQL="SELECT * FROM topic WHERE a_name LIKE '%".$search."%' AND a_status=1 AND a_year =$year ";
}
if($year!=0 && $status==2 && $search!="")
{
$strSQL="SELECT * FROM topic WHERE a_name LIKE '%".$search."%' AND a_year =$year ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 20; // Per Page
if(!isset($_GET["Page"]))
{ $Page=1; }
else
{ $Page = $_GET["Page"];}
$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 a_year DESC ,a_id DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="86%" border="1" align="center" cellpadding="3" cellspacing="0" class="coll">
<tr>
<th width="39" bgcolor="#99FF33">ลำดับ</th>
<th width="87" bgcolor="#99FF33"> เลขที่</th>
<th width="531" bgcolor="#99FF33"> ชื่อเรื่อง</th>
<th width="104" bgcolor="#99FF33"> วันที่</th>
</tr>
<?php
$i = 0;
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td align="center"><?=++$i?></td>
<td align="center"><?php echo $objResult["a_id"];?></td>
<td><?php echo $objResult["a_name"];?></td>
<td align="center"><?php $input=$objResult["a_date"];$dateinput = date_create("$input");echo $booking_day= date_format($dateinput,"d-m-Y");?></td>
</tr>
<?php
}
?>
</table>
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center">
<ul class="pagination">
<?php if($Num_Rows>10)
{ if($Prev_Page)
{echo "<li><a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a></li>";}
for($i=1; $i<=$Num_Pages; $i++)
{
if($i != $Page)
{echo "<li><a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a></li>";}
else
{ echo "<li><a class=active href=#>$i</a></li>";}
}
if($Page!=$Num_Pages)
{echo "<li><a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a></li> ";}
}
?>
</ul></td>
</tr>
</table>
</body>
</html>
Tag : PHP, CSS, Ajax, jQuery, XAMPP
|
|
|
|
|
|
Date :
2018-02-21 09:45:10 |
By :
bb |
View :
1394 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|