|
 |
|
ถามเรื่องทำระบบ search โดยการส่งค่า POST ด้วย jquery |
|
 |
|
|
 |
 |
|
Code (PHP)
<script type="text/javascript">
$(document).ready(function(){
$.post("customersearch.php", { data1:""},function(result){
$("#div1").html(result);
});
$("#btn1").click(function(){
$.post("customersearch.php", {
data1: $("#txt1").val(),
data2: $("#txt2").val()},
function(result){
$("#div1").html(result);
}
);
});
});
</script>
|
 |
 |
 |
 |
Date :
2014-02-10 12:23:16 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Example search โดยการส่งค่า POST และ Pagination ด้วย jquery ลองประยุคใช้ดูครับ
article.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<input type="search" id="seArtile" />
<div id="divSearch">
</div>
<script src="bootstrap/js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(e) {
Record('',1);
$('#seArtile').keyup(function(){
Record($(this).val(),1);
});
});
function Record(Article,Page){
var divSearch=$('#divSearch').empty();
$.ajax({url:"record_article.php",
async:false,
cache:false,
global:false,
type:"POST",
data:"Article="+Article+
"&Page="+Page,
success: function(result){
divSearch.html(result);
}
});
}
</script>
record_article.php
Code (PHP)
<?php
include("module/php/config.inc.php");
include("module/php/function.inc.php");
$Article=mysql_real_escape_string($_POST['Article']);
$Page=mysql_real_escape_string($_POST['Page']);
$select=select("active_article","WHERE Article LIKE '%".$Article."%'");
$PerPage=2;
$num_rows=numRows($select);
if($Page == ''){
$Page=1;
}
$PageStart=($PerPage*$Page)-$PerPage;
if($num_rows <= $PerPage){
$num_pages=1;
}else if(($num_rows % $PerPage)==0){
$num_pages=$num_rows/$PerPage;
}else{
$num_pages=ceil($num_rows/$PerPage);
}
?>
<table border="0">
<tr>
<td>หัวข้อ</td>
</tr>
<?php
$select=select("active_article","WHERE Article LIKE '%".$Article."%' LIMIT $PageStart,$PerPage");
while($Arti=mysql_fetch_array($select)){
?>
<tr>
<td><?php echo $Arti['Article']?></td>
</tr>
<tr>
<?php
}
?>
<td>
<select id="selPage" onChange="Record($('#seArtile').val(),$(this).val());">
<option value="">0</option>
<?php
for($i=1;$i<=$num_pages;$i++){
if($Page==$i){
$sel="selected";
}else{
$sel="";
}
echo "<option value=\"$i\" $sel>$i</option>";
}
?>
</select>
</td>
</tr>
</table>
|
ประวัติการแก้ไข 2014-02-10 14:02:10
 |
 |
 |
 |
Date :
2014-02-10 14:01:02 |
By :
Ex-[S]i[L]e[N]t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|