อยากทำ code แบ่งหน้าเว็บบอร์ด อะคับ ต้องทำยังไงมั้งคับ ช่วยผมด้วยคับผมทำไม่เป็น จาก เด็กโง่ หัดเขียนเว็บ
<?
include "connect.php";
include "function.php";
$Page=$_GET['Page'];
$Per_Page=5; //จำนวนต่อหน้า
$sql="select * from tb_question order by id_ques desc";
if(!$Page)
$Page=1;
$Prev_Page=$Page-1;
$Next_Page=$Page+1;
$result=mysql_db_query($db_name,$sql);
$Page_start=($Per_Page*$Page)-$Per_Page;
$Num_Rows=mysql_num_rows($result);
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;
if(($Page>$Num_Pages) || ($Page<0))
echo "จำนวน $Page มากกว่า $Num_Pages";
$sql.=" LIMIT $Page_start , $Per_Page ";
$result=mysql_db_query($db_name,$sql);
echo "
<h3> Webboard กระทู้ ถาม - ตอบ</h3>
<a href='guestion_form.php'>ตั้งคำถามใหม่</a><p>
<table width='105%' border='1'>
<tr bgcolor='#D2E9FF'>
<td width='8%'><center><b><font size='2' face='MS Sans Serif'>รหัส</font></b></center></td>
<td width='61%'> <center><b><font size='2' face='MS Sans Serif'>หัวข้อคำถาม</font></b></center></td>
<td width='15%'> <center><b><font size='2' face='MS Sans Serif'>ผู้ตั้งคำถาม</font></b></center></td>
<td width='16%'> <center><b><font size='2' face='MS Sans Serif'>ตั้งเมื่อวันที่</font></b></center></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=nl2br(htmlspecialchars($detail_ques));
$date_ques=displaydate($date_ques);
echo "
<tr bgcolor='#FFFFFF'>
<td width='8%'><center><font size='2' face='MS Sans Serif'>#$id_ques</font></center></td>
<td width='61%'> <font size='2' face='MS Sans Serif'><a href='answer_view.php?id_ques=$id_ques'>$title_ques</a></font></td>
<td width='15%'> <center><font size='2' face='MS Sans Serif'>$name_ques</font></center></td>
<td width='16%'> <center><font size='2' face='MS Sans Serif'>$date_ques</font></center></td>
</tr>";
} // end while
echo "</table>";
if ($Prev_Page)
echo "<a href=\"$PHP_SELF?Page=$Prev_Page\"><<</a>";
for($i=1;$i<=$Num_Pages;$i++)
{
if($i!=$Page)
echo "[<a href=\"$PHP_SELF?Page=$i\">$i</a>]";
else
echo "<b>หน้า $i</b>";
}
if($Page!=$Num_Pages)
echo "<a href=\"$PHP_SELF?Page=$Next_Page\">>></a>";
?>
Date :
9 มี.ค. 2551 18:50:14
By :
ikai_27
ขอขอบคุณ คุณ ikai_27 มากคับ
Date :
9 มี.ค. 2551 23:06:35
By :
เด็กโง่
ถ้าจะกรุณา ได้ Code search จะเป็นพระคุณอย่างยิ่งคับ แต่ถ้าไม่ว่างก้อไม่เป็นไรคับ ..
ขอบคุณอีกครั้งคับ
Date :
10 มี.ค. 2551 06:08:42
By :
เด็กโง่
<?
include "connect.php";
include "function.php";
$Page=$_GET['Page'];
$search=$_GET['search'];
$Per_Page=5; //จำนวนต่อหน้า
if ($search)
$sql="select * from `tb_question` WHERE (`title_ques` like '%$search%') OR (`detail_ques` like '%$search%') order by `id_ques` desc";
else
$sql="select * from `tb_question` order by `id_ques` desc";
if(!$Page)
$Page=1;
$Prev_Page=$Page-1;
$Next_Page=$Page+1;
$result=mysql_db_query($db_name,$sql);
$Page_start=($Per_Page*$Page)-$Per_Page;
$Num_Rows=mysql_num_rows($result);
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;
if(($Page>$Num_Pages) || ($Page<0))
echo "จำนวน $Page มากกว่า $Num_Pages";
$sql.=" LIMIT $Page_start , $Per_Page ";
$result=mysql_db_query($db_name,$sql);
echo "
<h3> Webboard กระทู้ ถาม - ตอบ</h3>
<a href='guestion_form.php'>ตั้งคำถามใหม่</a><p>
<form action=\"\" method=\"get\" name=\"search\">
<div align=\"right\"> <strong> Search</strong> <input name=\"search\" type=\"text\" style=\"width:160;height:19\" />
<input type=\"submit\" name=\"Submit\" value=\"Go!\" />
</div>
</form>
<table width='105%' border='1'>
<tr bgcolor='#D2E9FF'>
<td width='8%'><center><b><font size='2' face='MS Sans Serif'>รหัส</font></b></center></td>
<td width='61%'> <center><b><font size='2' face='MS Sans Serif'>หัวข้อคำถาม</font></b></center></td>
<td width='15%'> <center><b><font size='2' face='MS Sans Serif'>ผู้ตั้งคำถาม</font></b></center></td>
<td width='16%'> <center><b><font size='2' face='MS Sans Serif'>ตั้งเมื่อวันที่</font></b></center></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=nl2br(htmlspecialchars($detail_ques));
$date_ques=displaydate($date_ques);
echo "
<tr bgcolor='#FFFFFF'>
<td width='8%'><center><font size='2' face='MS Sans Serif'>#$id_ques</font></center></td>
<td width='61%'> <font size='2' face='MS Sans Serif'><a href='answer_view.php?id_ques=$id_ques'>$title_ques</a></font></td>
<td width='15%'> <center><font size='2' face='MS Sans Serif'>$name_ques</font></center></td>
<td width='16%'> <center><font size='2' face='MS Sans Serif'>$date_ques</font></center></td>
</tr>";
} // end while
echo "</table>";
if ($Prev_Page)
echo "<a href=\"$PHP_SELF?search=$search&Page=$Prev_Page\"><<</a>";
for($i=1;$i<=$Num_Pages;$i++)
{
if($i!=$Page)
echo "[<a href=\"$PHP_SELF?search=$search&Page=$i\">$i</a>]";
else
echo "<b>หน้า $i</b>";
}
if($Page!=$Num_Pages)
echo "<a href=\"$PHP_SELF?search=$search&Page=$Next_Page\">>></a>";
?>
Date :
10 มี.ค. 2551 19:12:10
By :
ikai_27
พี่ คือ Hero ของผมโดย แท้ ขอบคุณจากใจจิง คับ คุณ ikai_27
Date :
10 มี.ค. 2551 23:46:44
By :
big
พอดี ผม ลอง ประยุกต์ ใช้ กับ หน้า รายการสินค้า ไม่เป็นไปตาม คาด ช่วยดูหน่อยคับว่าผิดตรงไหน
อันนี้ ต้นฉบับคับ
=======================================================================
<?
$id_type_select=$_GET[id_type];
?>
<HTML>
<HEAD><TITLE>ร้านค้าออนไลน์</TITLE><meta http-equiv="Content-Type" content="text/html; charset=windows-874"></HEAD>
<BODY>
<H2>:: ร้านค้าออนไลน์ ::</H2>
<P>
[ <A HREF="index.php">หน้าแรก</A> ]
[ <A HREF="basket.php">ดูตะกร้าสินค้า</A> ]
</P>
<TABLE WIDTH="770" BORDER="0">
<TR>
<TD WIDTH="174" HEIGHT="200" VALIGN="top" BGCOLOR="#EAEAEA">
<CENTER><B>ประเภทสินค้า</B></CENTER>
<?
include "connect.php";
include "type_list.php";
?>
</TD>
<TD WIDTH="580" VALIGN="top"><div align="center">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">
<?
$sql="select * from tb_product where ref_id_type='$id_type_select' ";
$result=mysql_db_query($dbname,$sql);
while ($rs=mysql_fetch_array($result)) {
$id_prd=$rs[id_prd];
$code=sprintf("%05d",$id_prd);
$name_prd=$rs[name_prd];
$detail_prd=$rs[detail_prd];
$ref_id_type=$rs[ref_id_type];
$price_prd=$rs[price_prd];
$photo_prd=$rs[photo_prd];
if ($photo_prd=="") {
$photo_prd="temp.jpg";
}
echo "<TR>
<TD WIDTH='20%' VALIGN='top'>
<IMG SRC='photo/$photo_prd'>
</TD>
<TD WIDTH='80%' VALIGN='top'>
<B>รหัสสินค้า :</B> $code <BR>
<B>ชื่อสินค้า : </B>$name_prd <BR>
<B>ราคา :</B> $price_prd บาท<BR><BR>
[ <A HREF='prd_view.php?id_prd=$id_prd'>แสดงรายละเอียด </A>]
[ <A HREF='basket_add.php?id_prd=$id_prd'>หยิบใส่ตะกร้า </A>] <BR>
</TD>
</TR>";
}
?>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Date :
11 มี.ค. 2551 15:19:13
By :
เด็กโง่
อันนี้จากที่ ผม ดัดแปลง ผิดพลาดตรงไหน คับ
========================================
<?
$id_type_select=$_GET[id_type];
?>
<HTML>
<HEAD><TITLE>ร้านค้าออนไลน์</TITLE><meta http-equiv="Content-Type" content="text/html; charset=windows-874"></HEAD>
<BODY>
<H2>:: ร้านค้าออนไลน์ ::</H2>
<P>
[ <A HREF="index.php">หน้าแรก</A> ]
[ <A HREF="basket.php">ดูตะกร้าสินค้า</A> ]
</P>
<TABLE WIDTH="770" BORDER="0">
<TR>
<TD WIDTH="174" HEIGHT="200" VALIGN="top" BGCOLOR="#EAEAEA">
<CENTER><B>ประเภทสินค้า</B></CENTER>
<?
include "connect.php";
include "type_list.php";
$Page=$_GET['Page'];
$search=$_GET['search'];
$Per_Page=5; //จำนวนต่อหน้า
if ($search)
$sql="select * from `tb_product` WHERE (`name_prd` like '%$search%') OR (`detail_prd` like '%$search%') order by `id_prd` desc";
?>
</TD>
<TD WIDTH="580" VALIGN="top"><div align="center">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">
<?
$sql="select * from tb_product where ref_id_type='$id_type_select' ";
if(!$Page)
$Page=1;
$Prev_Page=$Page-1;
$Next_Page=$Page+1;
$result=mysql_db_query($dbname,$sql);
$Page_start=($Per_Page*$Page)-$Per_Page;
$Num_Rows=mysql_num_rows($result);
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;
if(($Page>$Num_Pages) || ($Page<0))
echo "จำนวน $Page มากกว่า $Num_Pages";
$sql.=" LIMIT $Page_start , $Per_Page ";
$result=mysql_db_query($dbname,$sql);
echo "
<form action=\"\" method=\"get\" name=\"search\">
<div align=\"right\"> <strong> Search</strong> <input name=\"search\" type=\"text\" style=\"width:160;height:19\" />
<input type=\"submit\" name=\"Submit\" value=\"Go!\" />
</div>
</form>
<TR>
<TD WIDTH='20%' VALIGN='top'>
<IMG SRC='photo/$photo_prd'>
</TD>
<TD WIDTH='80%' VALIGN='top'>
<B>รหัสสินค้า :</B> $code <BR>
<B>ชื่อสินค้า : </B>$name_prd <BR>
<B>ราคา :</B> $price_prd บาท<BR><BR>
[ <A HREF='prd_view.php?id_prd=$id_prd'>แสดงรายละเอียด </A>]
[ <A HREF='basket_add.php?id_prd=$id_prd'>หยิบใส่ตะกร้า </A>] <BR>
</TD>
</TR>";
while ($rs=mysql_fetch_array($result)) {
$id_prd=$rs[id_prd];
$code=sprintf("%05d",$id_prd);
$name_prd=$rs[name_prd];
$detail_prd=$rs[detail_prd];
$ref_id_type=$rs[ref_id_type];
$price_prd=$rs[price_prd];
$photo_prd=$rs[photo_prd];
if ($photo_prd=="") {
$photo_prd="temp.jpg";
}
}
?>
<? echo "</table>";
if ($Prev_Page)
echo "<a href=\"$PHP_SELF?search=$search&Page=$Prev_Page\"><<</a>";
for($i=1;$i<=$Num_Pages;$i++)
{
if($i!=$Page)
echo "[<a href=\"$PHP_SELF?search=$search&Page=$i\">$i</a>]";
else
echo "<b>หน้า $i</b>";
}
if($Page!=$Num_Pages)
echo "<a href=\"$PHP_SELF?search=$search&Page=$Next_Page\">>></a>";
?>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Date :
11 มี.ค. 2551 15:22:31
By :
เด็กโง่
<?
$id_type_select=$_GET[id_type];
$Page=$_GET['Page'];
$search=trim($_GET['search'];
$Per_Page=5; //จำนวนต่อหน้า
?>
<HTML>
<HEAD><TITLE>ร้านค้าออนไลน์</TITLE><meta http-equiv="Content-Type" content="text/html; charset=windows-874"></HEAD>
<BODY>
<H2>:: ร้านค้าออนไลน์ ::</H2>
<P>
[ <A HREF="index.php">หน้าแรก</A> ]
[ <A HREF="basket.php">ดูตะกร้าสินค้า</A> ]</P>
<form name="form1" method="post" action="">
ค้นหา
<input name="search" type="text" id="search">
<input type="submit" name="Submit" value="GO!">
</form>
<TABLE WIDTH="770" BORDER="0">
<TR>
<TD WIDTH="174" HEIGHT="200" VALIGN="top" BGCOLOR="#EAEAEA">
<CENTER><B>ประเภทสินค้า</B></CENTER>
<?
include "connect.php";
include "type_list.php";
?>
</TD>
<TD WIDTH="580" VALIGN="top"><div align="center">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">
<?
if($search) // กำหนดค่าถ้ามีการค้นหาให้ค้นตามคำค้นที่ต้องการ
$sql="select * from `tb_product` WHERE (`name_prd` like '%$search%') OR (`detail_prd` like '%$search%') ";
else { // ถ้าไม่มีการ search ให้ทำการค้นหาตามประเภท
$sql="select * from tb_product where ref_id_type='$id_type_select' ";
}
if(!$Page)
$Page=1;
$Prev_Page=$Page-1;
$Next_Page=$Page+1;
$result=mysql_db_query($dbname,$sql);
$Page_start=($Per_Page*$Page)-$Per_Page;
$Num_Rows=mysql_num_rows($result);
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;
if(($Page>$Num_Pages) || ($Page<0))
echo "จำนวน $Page มากกว่า $Num_Pages";
$sql.=" LIMIT $Page_start , $Per_Page ";
$result=mysql_db_query($db_name,$sql);
while ($rs=mysql_fetch_array($result)) {
$id_prd=$rs[id_prd];
$code=sprintf("%05d",$id_prd);
$name_prd=$rs[name_prd];
$detail_prd=$rs[detail_prd];
$ref_id_type=$rs[ref_id_type];
$price_prd=$rs[price_prd];
$photo_prd=$rs[photo_prd];
if ($photo_prd=="") {
$photo_prd="temp.jpg";
}
echo "<TR>
<TD WIDTH='20%' VALIGN='top'>
<IMG SRC='photo/$photo_prd'>
</TD>
<TD WIDTH='80%' VALIGN='top'>
<B>รหัสสินค้า :</B> $code <BR>
<B>ชื่อสินค้า : </B>$name_prd <BR>
<B>ราคา :</B> $price_prd บาท<BR><BR>
[ <A HREF='prd_view.php?id_prd=$id_prd'>แสดงรายละเอียด </A>]
[ <A HREF='basket_add.php?id_prd=$id_prd'>หยิบใส่ตะกร้า </A>] <BR>
</TD>
</TR>";
}
?>
</TABLE>
</TD>
</TR>
</TABLE>
<?
if ($Prev_Page)
echo "<a href=\"$PHP_SELF?id_type=$id_type_select&search=$search&Page=$Prev_Page\"><<</a>";
for($i=1;$i<=$Num_Pages;$i++)
{
if($i!=$Page)
echo "[<a href=\"$PHP_SELF?id_type=$id_type_select&search=$search&Page=$i\">$i</a>]";
else
echo "<b>หน้า $i</b>";
}
if($Page!=$Num_Pages)
echo "<a href=\"$PHP_SELF?id_type=$id_type_select&search=$search&Page=$Next_Page\">>></a>";
?>
</BODY>
</HTML>
Date :
11 มี.ค. 2551 19:56:46
By :
ikai_27
Load balance : Server 05