 |
พบปัญหา การแบ่งหน้า php คือเราให้มันตัดที่2 กระทู้พอกระทู้ที่3 จะขึ้นหน้าใหม่นี่มันไม่ขึ้นให้อาคะ |
|
 |
|
|
 |
 |
|
ติด register global ครับ เปลี่ยน $page เป็น $_GET["page"]
|
 |
 |
 |
 |
Date :
2009-07-14 12:17:45 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
if(isset($page)){
$pageno = $page;
$start = $pagesize*($pageno-1);
}else{
$pageno = 1;
$start = 0;
}
?>
เปลี่ยนเฉพาะ $page หรอคะ ยังไม่ได้อยู่ดีอ่าคะ
Code (PHP)
<?php
if(isset($_GET["page"])){
$pageno = $_GET["page"];
$start = $pagesize*($pageno-1);
}else{
$pageno = 1;
$start = 0;
}
?>
|
 |
 |
 |
 |
Date :
2009-07-14 13:21:38 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอ๋ ลอง echo $sql ออกมาดูครับ ว่ามันถูกต้องหรือเปล่า
|
 |
 |
 |
 |
Date :
2009-07-14 13:28:57 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$page หรือ $_GET["page"] ค่าออกมาเหมือนกันเลยคะ(ตามที่ตั้งกระทู้ไว้)
|
 |
 |
 |
 |
Date :
2009-07-14 13:43:59 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอมาใช้โค๊ดของพี่ มันก็ไม่ยอม แบ่งให้อีกนะคะ งงเลย แต่มันไม่เออเรอร์นะคะ
Code (PHP)
<?php
<?
include "connectdb.php";
include "function.php";
$sql="SELECT * FROM tb_question order by id_ques desc";
$result =mysql_query($sql);
echo "<table width='540' border='0' align='center'>
<tr><td><b align='left' class='style16' style='padding-left:5px; font-size:16px'>รวมกระทู้ถาม-ตอบ</b>
<div align='right' style='padding-right:5px; padding-bottom:2px;'><a href='question_form.php'><img src='images/ne.png' border='0' /></a></div></td></tr>
<tr><td><div align='center' ><img src='images/lineheader.gif' width='540' border='0' /></div></td></tr>
<table width='540' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#dadada' style='border-style:dotted'>
<tr >
<td width='540' background='images/bg_list.gif'><table width='540' border='1' cellspacing='0' bordercolor='#dadada'>
</tr>
<tr>
<td width='50' class='style16' align='center'>ID</td>
<td width='300' class='style16' align='center'>Topics</td>
<td width='90' class='style16' align='center'>Author</td>
<td width='100' class='style16' align='center'>Date</td>
</tr>";
while ($record=mysql_fetch_array($result)) {
$id_ques=$record[id_ques];
$title_ques=$record[title_ques];
$detail_ques=$record[detail_ques];
$name_ques=$record[name_ques];
$email_ques=$record[email_ques];
$date_ques=$record[date_ques];
$title_ques=htmlspecialchars($title_ques);
$name_ques=htmlspecialchars($name_ques);
$detail_ques=wordwrap(nl2br(htmlspecialchars($detail_ques)),30,"\n",true);
$date_ques=displaydate($date_ques);
echo "<tr bgcolor='#ffffff'>
<td width='50' class='style16' ><center><img src='images/leaf.gif' border='0' />$id_ques</center></td>
<td width='300' class='style16' ><a href='answer_view.php?id_ques=$id_ques'>$title_ques</a></td>
<td width='90' class='style16' ><center>$name_ques</center></td>
<td width='100' class='style16' ><center>$date_ques</center></td>
</tr>";
}//end while
echo" <td colspan='4' background='images/bg_list.gif' class='style17'> </td>
</tr>
</table></td>
</tr>
</table>";
?>
<?
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 2; <<<<< แสดง 2 กระทู้เพื่อทดสอบคะ
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM tb_question". $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));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){ <<<<<อันนี้ขอความรู้เพิ่มmysql_fetch_assoc ไว้ทำอะไรคะ
echo $rows["id"]; <<<< ถ้าอยากให้โชว์เลขหน้าอย่างเดียวก็ไม่ต้อง echo ใช่รึเปล่าคะ
}
echo "\n<div class='text' style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, "current_page","other_page",$send) . " </div><div class='text' style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
?>
รูปประกอบ

|
 |
 |
 |
 |
Date :
2009-07-14 15:21:11 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่วน function page_navi อยู่ ในส่วนของ head ไม่ได้เปลี่ยนแปลงค่าอะไรเลย
|
 |
 |
 |
 |
Date :
2009-07-14 15:26:51 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเอาโค๊ดข้างบนมาแก้นะครับ ลองดู
Code (PHP)
<?php
include "connectdb.php";
include "function.php";
echo "<table width='540' border='0' align='center'>
<tr><td><b align='left' class='style16' style='padding-left:5px; font-size:16px'>รวมกระทู้ถาม-ตอบ</b>
<div align='right' style='padding-right:5px; padding-bottom:2px;'><a href='question_form.php'><img src='images/ne.png' border='0' /></a></div></td></tr>
<tr><td><div align='center' ><img src='images/lineheader.gif' width='540' border='0' /></div></td></tr>
<table width='540' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#dadada' style='border-style:dotted'><tr >
<td width='540' background='images/bg_list.gif'><table width='540' border='1' cellspacing='0' bordercolor='#dadada'>
</tr>
<tr>
<td width='50' class='style16' align='center'>ID</td>
<td width='300' class='style16' align='center'>Topics</td>
<td width='90' class='style16' align='center'>Author</td>
<td width='100' class='style16' align='center'>Date</td>
</tr>";
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id_ques = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM tb_question". $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));
if($total > 0){
while ($record=mysql_fetch_array($result)) {
$id_ques=$record[id_ques];
$title_ques=$record[title_ques];
$detail_ques=$record[detail_ques];
$name_ques=$record[name_ques];
$email_ques=$record[email_ques];
$date_ques=$record[date_ques];
$title_ques=htmlspecialchars($title_ques);
$name_ques=htmlspecialchars($name_ques);
$detail_ques=wordwrap(nl2br(htmlspecialchars($detail_ques)),30,"\n",true);
$date_ques=displaydate($date_ques);
echo "<tr bgcolor='#ffffff'>
<td width='50' class='style16' ><center><img src='images/leaf.gif' border='0' />$id_ques</center></td>
<td width='300' class='style16' ><a href='answer_view.php?id_ques=$id_ques'>$title_ques</a></td>
<td width='90' class='style16' ><center>$name_ques</center></td>
<td width='100' class='style16' ><center>$date_ques</center></td>
</tr>";
}//end while
echo" <td colspan='4' background='images/bg_list.gif' class='style17'> </td>
</tr>
</table></td>
</tr>
</table>";
echo "\n<div class='text' style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, "current_page","other_page",$send) . " </div><div class='text' style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
?>
|
 |
 |
 |
 |
Date :
2009-07-14 22:04:25 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนเดิมอะคะ
แต่ลอง echo บรรทัดนี้ $sql = "SELECT * FROM tb_question". $condition;
ได้
SELECT * FROM tb_question order by id_ques desc = 'SELECT * FROM tb_question'.
|
 |
 |
 |
 |
Date :
2009-07-15 09:43:47 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่ถ้าเอาโค๊ดพี่มาแปะ มัฟ้องเออเรอร์นะคะ
Parse error: syntax error, unexpected $end in C:\AppServ\www\Worldtext\service.php on line 220
ซึ่ง line 220 เป็น </html>
|
 |
 |
 |
 |
Date :
2009-07-15 09:47:19 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้อีกหรอครับ เอาไฟล์นั้นอัปขี้น server ฝากไฟล์แล้วเอามาโพสต์ไว้ อยากรู้จริงๆ มันผิดตรงไหน
|
 |
 |
 |
 |
Date :
2009-07-15 10:51:16 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดู { } ครับว่าขาดเกินไปหรือเปล่า
|
 |
 |
 |
 |
Date :
2009-07-15 10:53:46 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ทำไฟล์ ที่ตั้งกระทู้ แก้ได้แล้วคะ query ผิดตัว
ขอบคุณมากๆนะคะ
|
 |
 |
 |
 |
Date :
2009-07-15 11:16:31 |
By :
SG14 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยินดีด้วย 
|
 |
 |
 |
 |
Date :
2009-07-15 21:36:39 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|