|
 |
|
ปัญหาการแบ่งหน้ากับการค้นหา หน้าแสดงข้อมูลเป็นแบบนี้นะค่ะ พอค้นหาเสร็จ จะเป็นแบบนี้ค่ะ |
|
 |
|
|
 |
 |
|
หน้าแสดงข้อมูลเป็นแบบนี้นะค่ะ

พอค้นหาเสร็จ จะเป็นแบบนี้ค่ะ

แต่ถ้ากดเลือก หน้า 1 หรือ 2 มันจะกลับไปหน้าแสดงข้อมูลเลยค่ะ(รูปแรก)
ช่วยดูโค้ดให้หน่อยเถอะค่ะ จนปัญญาแล้วจริง ๆ
Code (PHP)
<body>
<script >
function check(){
if(document.form.keyword.value == ""){
alert("กรุณากรอกคำค้น");
document.form.keyword.focus();
return false;
}
return true;
}
</script>
<?php
function page_navi($page, $limit, $range, $count, $current_style="", $other_style="", $quetystring=""){
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send = !empty($querystring)? "&". $querystring : "";
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
echo "<a href=\"?page=1" . $send . "\" target=\"" . $target . "\">«</a> ";
echo "<a href=\"?page=$navi_back" . $send . "\" target=\"" . $target . "\">‹</a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
echo "<a href=\"?page=$i" . $send . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
else
echo "<a href=\"?page=$i" . $send . "\" target=\"" . $target . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
echo "<a href=\"?page=$navi_next" . $send . "\" target=\"" . $target . "\">›</a> ";
if(($page+1) < $total)
echo "<a href=\"?page=$total" . $send . "\" target=\"" . $target . "\">»</a>";
}
}
include ("config-db.php");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 5;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE acaserv_id = '" . $_GET["id"]. "' ORDER BY acaserv_id DESC";
}
$sql = "SELECT * FROM tb_acaserv". $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $link);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $link));
?>
<form name="form" action="" method="post" onsubmit="return check();" >
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><font size="3" color="#0684be"><b> โครงการบริการวิชาการ</b></font></td></tr>
<tr><td background="pic/line_midbtm.jpg"> </td></tr>
<tr><td>
<table align="center" width="80%" border="0" cellpadding="2" cellspacing="2">
<tr height="20"><td></td></tr>
<tr>
<td align="right" width="150"><font size="2"> คำค้น : </font></td>
<td ><input type="text" name="keyword" id="keyword" size="32" maxlength="20" onKeyDown="if(event.keyCode==13) event.keyCode=9;" /></td>
</tr>
<tr>
<td align="right" width="150"><font size="2"> ค้นหาโดย : </font></td>
<td><input type="radio" name="Sname" value="ชื่องานวิจัย" checked="checked" /><font size="2">ชื่อโครงการบริการวิชาการ</font>
<input type="radio" name="Sname" value="ชื่อนักวิจัย" /><font size="2">ชื่อหัวหน้าโครงการบริการวิชาการ</font>
</td>
</tr>
<tr>
<td align="right" width="150"></td>
<td>
<? if (!$submit) { ?>
<input type="submit" name="submit" id="submit" value="ค้นหา" />
</td>
</tr>
</table>
</td></tr>
<tr height="10"><td></td></tr>
<tr>
<td>
<table align="center" width="100%" border="1" bordercolor="#FFFFFF" cellpadding="2" cellspacing="1">
<tr align="center" bgcolor="#FFCCCC" height="30">
<td width="7%"><font size="2" color="#2756D1"><b>ลำดับ</b></font></td>
<td width="60%"><font size="2" color="#2756D1"><b>ชื่อโครงการบริการวิชาการ</b></font></td>
<td width="23%"><font size="2" color="#2756D1"><b>ชื่อหัวหน้าโครงการ</b></font></td>
<td width="10%"><font size="2" color="#2756D1"><b>ปีงบประมาณ</b></font></td>
</tr>
<?php
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
?>
<tr><td align="center" width="7%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows["acaserv_id"] ; ?></font></td>
<td width="60%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows["acaserv_name"] ; ?></font></td>
<td width="23%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows["researcher"] ; ?></font></td>
<td align="center" width="10%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows["year"];?></font></td>
</tr>
<?php
}
}else{
?>
<tr><td colspan="4" bgcolor="#CCE9FD" align="center">ไม่มีข้อมูล</td></tr>
</table>
<?
}
?>
<table align="center" width="100%" border="0" bordercolor="#0000FF">
<tr height="10"></tr>
<tr><td><font size="2"><b>จำนวนโครงการบริการวิชาการทั้งหมด <? echo "$total <div style=\"float:right;\">จำนวน [". ($limit_start+1) . "-" . ($limit_start+$count) . "] รายการ</div>" ;?> รายการ</b></font></td></tr>
<tr height="10"></tr>
<tr align="center"><td>
<font size=2><b><?php echo"<font color=#FF6600>หน้า $page</font>" ;?></b></font>
</td></tr>
<tr align="center"><td>
<?php echo page_navi($page, $limit_end, 2, $total, "current_page","other_page",$send);?>
</td></tr>
<tr height="10"></tr>
</table>
</td>
</tr>
</table>
</form>
<?php
}else{
function page_navi1($page1, $limit1, $range1, $count1, $current_style1="", $other_style1="", $quetystring1=""){
$total1 = ceil($count1/$limit1);
$navi_start1= $page1-$range1;
$navi_end1 = $page1+$range1;
$send1 = !empty($querystring1)? "&". $querystring1 : "";
if($navi_start1 <= 0) $navi_start1 = 1;
if($navi_end1 >= $total1) $navi_end1 = $total1;
if($page1>1){
$navi_back1 = $page1-1;
if($page1 > 2)
echo "<a href=\"?page1=1" . $send1 . "\" target1=\"" . $target1 . "\">«</a> ";
echo "<a href=\"?page1=$navi_back1" . $send1 . "\" target1=\"" . $target1 . "\">‹</a> ";
}
for($j = $navi_start1; $j <= $navi_end1; $j++){
if($j == $page1)
echo "<a href=\"?page1=$j" . $send1 . "\" target1=\"" . $target1 . "\"><strong>$j</strong></a> ";
else
echo "<a href=\"?page1=$j" . $send . "\" target1=\"" . $target1 . "\">$j</a> ";
}
if($page1 < $total1){
$navi_next1 = $page1+1;
echo "<a href=\"?page1=$navi_next1" . $send1 . "\" target1=\"" . $target1 . "\">›</a> ";
if(($page1+1) < $total1)
echo "<a href=\"?page1=$total1" . $send1 . "\" target1=\"" . $target1 . "\">»</a>";
}
}
include ("config-db.php");
$keyword = trim($_POST['keyword']);
$page1 = (isset($_REQUEST['page1']))? intval($_REQUEST['page1']) : 1;
$limit_end1 = 3;
$limit_start1 = ($page1-1)*$limit_end1;
if(isset($keyword) and $keyword != ""){
$send1 = "keyword=". $keyword;
$condition1= " WHERE acaserv_id LIKE '%" . $keyword . "%'";
}
$sql1 = "SELECT * FROM tb_acaserv". $condition1;
$query_id1 = mysql_query($sql1. " LIMIT " . $limit_start1. "," . $limit_end1, $link);
$count1 = mysql_num_rows($query_id1);
$total1 = mysql_num_rows(mysql_query($sql1, $link));
?>
<input type="submit" name="submit" id="submit" value="ค้นหา" />
</td>
</tr>
</table>
</td></tr>
<tr height="20"><td></td></tr>
<tr>
<td>
<?
echo " ผลการค้นหาคำว่า <font color=#FF0000>$keyword</font>"
?>
<table align="center" width="100%" border="1" bordercolor="#FFFFFF" cellpadding="2" cellspacing="1">
<tr align="center" bgcolor="#FFCCCC" height="30">
<td width="7%"><font size="2" color="#2756D1"><b>ลำดับ</b></font></td>
<td width="60%"><font size="2" color="#2756D1"><b>ชื่อโครงการบริการวิชาการ</b></font></td>
<td width="23%"><font size="2" color="#2756D1"><b>ชื่อหัวหน้าโครงการ</b></font></td>
<td width="10%"><font size="2" color="#2756D1"><b>ปีงบประมาณ</b></font></td>
</tr>
<?php
if($total1 > 0){
while($rows1 = mysql_fetch_assoc($query_id1)){
?>
<tr><td align="center" width="7%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows1["acaserv_id"] ; ?></font></td>
<td width="60%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows1["acaserv_name"] ; ?></font></td>
<td width="23%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows1["researcher"] ; ?></font></td>
<td align="center" width="10%" bgcolor="#CCE9FD"><font size="2"><?php echo $rows1["year"];?></font></td>
</tr>
<?php
}
}else{
?>
<tr><td colspan="4" bgcolor="#CCE9FD" align="center">ไม่พบข้อมูลที่ต้องการ</td></tr>
</table>
<?
}
?>
<table align="center" width="100%" border="0" bordercolor="#0000FF">
<tr height="10"></tr>
<tr><td><font size="2"><b>จำนวนโครงการบริการวิชาการทั้งหมด <? echo "$total1 <div style=\"float:right;\">จำนวน [". ($limit_start1+1) . "-" . ($limit_start1+$count1) . "] รายการ</div>" ;?> รายการ</b></font></td></tr>
<tr height="10"></tr>
<tr align="center"><td>
<font size=2><b><?php echo"<font color=#FF6600>หน้า $page1</font>" ;?></b></font>
</td></tr>
<tr><td align="center">
<?php
echo "ผลการค้นหา : ";
echo "<div>".page_navi1($page1, $limit_end1, 2, $total1, "current_page1","other_page1",$send1)."</div>";
?>
</td></tr>
<tr height="10"></tr>
</table>
</td>
</tr>
</table>
<?
}
mysql_close($link) ;
?>
</body>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-05-02 01:05:08 |
By :
ohanaa |
View :
830 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไหนละรูป
|
 |
 |
 |
 |
Date :
2010-05-02 09:59:09 |
By :
onedan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รูปที่ 1

รูปที่2

|
 |
 |
 |
 |
Date :
2010-05-02 12:21:07 |
By :
ohanaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยตอบหน่อยนะค่ะ
^^
|
 |
 |
 |
 |
Date :
2010-05-02 13:38:37 |
By :
ohanaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
    
|
 |
 |
 |
 |
Date :
2010-05-02 14:57:10 |
By :
jaaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|