|
|
|
code php ให้แสดงผลข้อมูลที่ค้นหาเจอทีละ 20 บรรทัด code php ให้แสดงผลข้อมูลที่ค้นหาเจอทีละ 20 บรรทัด |
|
|
|
|
|
|
|
ลองเอาไปศึกษาดูนะค่ะ
Code (PHP)
<form method="post" name="form_test">
<?
if(!isset($start)){
$start = 0;
}
$limit = '10'; // แสดงผลหน้าละกี่หัวข้อ
/* หาจำนวน record ทั้งหมด
ปล. อันนี้ต้องใช้กับตัวแบ่งนะ ห้ามเอาออก*/
$Qtotal = mysql_query("select * from product "); //คิวรี่ คำสั่ง
$total = mysql_num_rows($Qtotal); // หาจำนวน record
/* คิวรี่ข้อมูลออกมาเพื่อแสดงผล */
$Query = mysql_query("select * from product ORDER BY ID_Pro DESC LIMIT $start,$limit"); //คิวรี่คำสั่ง
$totalp = mysql_num_rows($Query); // หาจำนวน record ที่เรียกออกมา
$intRows = 0;
?>
<table width="800" align="center">
<tr>
<?
while($arr = mysql_fetch_array($Query)){
$intRows++;
echo "<td>";
?>
<table width="91" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="../admin/Product/images_product/<?=$arr["Image_Pro"];?>" target="_blank"><img src="../admin/Product/images_product/<?=$arr["Image_Pro"];?>" width="100" height="100" border="0"></a></div></td>
</tr>
<tr>
<td><div align="left"><span class="narmal3old"><?=$arr["Name_Pro"];?></span></div></td>
</tr>
<tr>
<td><div align="left"><span class="narmal3old">Price: <?=$arr["Price_Pro"];?> BATH/<?=$arr["Unit"];?></span></div></td>
</tr>
<tr>
<td><div align="left"><span class="narmal3old">Color: <?=$arr["Color_Pro"];?></span></div></td>
</tr>
<tr>
<td ><div align="left"><span class="narmal3old">Size: <?=$arr["Size_Pro"];?></span></div></td>
</tr>
</table>
<?
echo"</td>";
if(($intRows)%5==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
//echo"</tr></table>";
?>
</tr>
</table>
<?
$page = ceil($total/$limit); // เอา record ทั้งหมด หารด้วย จำนวนที่จะแสดงของแต่ละหน้า
/* เอาผลหาร มาวน เป็นตัวเลข เรียงกัน เช่น สมมุติว่าหารได้ 3 เอามาวลก็จะได้ 1 2 3 */
for($i=1;$i<=$page;$i++){
if($_REQUEST['page']==$i){ //ถ้าตัวแปล page ตรง กับ เลขที่วนได้
echo "[<a href='?start=".$limit*($i-1)."&page=$i'><B>$i</B></A>]"; //ลิ้งค์ แบ่งหน้า เงื่อนไขที่ 1
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i'>$i</A>]"; //ลิ้งค์ แบ่งหน้า เงื่อนไขที่ 2
}
}
?>
</form>
|
|
|
|
|
Date :
2010-07-06 11:54:07 |
By :
LuckyStar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP) จริงๆ แล้วผมกำหนดหน้าได้แล้วในการโชว์ข้อมูล แต่ว่าเมื่อเจอข้อมูลแล้วเลือกหน้าถัดไปแล้วมันไม่เจอหน้าถัดไป ต้องให้ค้นหาใหม่ครับ ไม่รู้ว่าติดตรงไหน
ผมว่าน่าจะเกี่ยวกับ if($_GET["txtKeyword"] != "")
{
<CENTER><form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Keyword <select name="txtKeyword">
<option value="TUMBON" <? if($txtKeyword=="TUMBON"){ ?>selected<? }?>>µÓºÅ</option>
<option value="IDM" <? if($txtKeyword=="IDM"){ ?>selected<? }?>>ÃËÑʺѵûÃЪҪ¹</option>
<option value="PNAME" <? if($txtKeyword=="PNAME"){ ?>selected<? }?>>ª×èͺؤ¤Å</option>
<option value="tCalendar " <? if($txtKeyword=="tCalendar "){ ?>selected<? }?>>Çѹà¡Ô´¼Ùé¢Öé¹·ÐàºÕ¹</option>
<option value="DAY2 " <? if($txtKeyword=="DAY2 "){ ?>selected<? }?>>à´×͹·Õè¢Öé¹·ÐàºÕ¹</option>
<option value="DAY3 " <? if($txtKeyword=="DAY3 "){ ?>selected<? }?>>»Õ·Õè¢Öé¹·ÐàºÕ¹</option>
<!-- <option value="MOO " <? if($txtKeyword=="MOO "){ ?>selected<? }?>>ËÁÙè·Õè</option> -->
</select>
<input name="Search" type="text" size="20" value="<? echo $Search?>">
<input type="submit" name="submit" value="Search"> <a href="#" class="hintanchor" onMouseover="showhint('¤é¹¨Ò¡ ª×èÍâ´ÂµÃ§/ ¾.È·Õèà¡Ô´/ ª×è͵ӺŠ/ÃËÑʺѵûÃЪҪ¹ 13 ËÅÑ¡/Çѹ·Õèŧ·ÐàºÕ¹/à´×͹/»Õ àÅ×Í¡ 1 ¤Ó¤é¹ËÒà·èÒ¹Ñé¹', this, event, '150px')">[?]</a>
<BR><BR>
<font size='2' face='MS Sans Serif' color="#000000" ><a href="index.php" ><strong>˹éÒËÅÑ¡</strong></font>
<font size='2' face='MS Sans Serif' color="#000000" ><a href="Register.php" target="_blank"><strong>à¾ÔèÁ¢éÍÁÙÅ</strong></font>
<font size='2' face='MS Sans Serif' color="#000000" ><a href="show_a.php" target="_blank"><strong>´Ù¢éÍÁÙÅ·Ñé§ËÁ´</strong></font> <BR><BR>
</a>
</tr>
</table>
</form></CENTER>
<?
if($_GET["txtKeyword"] != "")
{
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("bass");
mysql_query("SET NAMES UTF8");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
mysql_query("SET character_set_results='tis620'");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
mysql_query("SET character_set_client='tis620'");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
mysql_query("SET character_set_connection='tis620'");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
mysql_query("collation_connection = tis620_thai_ci");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
mysql_query("collation_database = tis620_thai_ci");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
mysql_query("collation_server = tis620_thai_ci");// ÃٻẺ¡ÒÃáÊ´§¢éÍÁÙÅ
// Search By Name or Email
$strSQL = "SELECT * FROM history WHERE (IDM LIKE '%".$_GET["Search"]."%' or PNAME LIKE '%".$_GET["Search"]."%' or TUMBON LIKE '%".$_GET["Search"]."%'or tCalendar LIKE '%".$_GET["Search"]."%'or MOO LIKE '%".$_GET["Search"]."%'or DAY2 LIKE '%".$_GET["Search"]."%'or DAY3 LIKE '%".$_GET["Search"]."%')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
echo "<font size='4' face='MS Sans Serif' color='#000000' ><strong> áÊ´§¼Å¡Òäé¹ËÒ¢éÍÁÙÅ·ÕèÁÕ¤ÓÇèÒ<strong> ". $_GET["Search"];" </font>";
$Per_Page = 2; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$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 id ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
while($row_show = mysql_fetch_array($objQuery))
{
echo"<table width='1000' border='1' height='100%' >";
echo"<tr bgcolor=#FF99FF>";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ÅӴѺ·Õè</strong>".$row_show['id'];
echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>Çѹ·Õè</strong> ".$row_show['DAY1']; echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>à´×͹</strong> ".$row_show['DAY2']; echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>¾.È.</strong> ".$row_show['DAY3']; echo "</font>";
echo" <BR><BR>";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>ª×èÍ-¹ÒÁÊ¡ØÅ</strong> ".$row_show['PTNAME'].$row_show['PNAME'];
echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong></strong> ".$row_show['LNAME'];
echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>Çѹ·Õèàà¡Ô´</strong> " . $row_show['tCalendar'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ÍÒÂØ</strong>" .$row_show['TOTAL'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ÊѪҵÔ</strong>" .$row_show['NATIONAL'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>àºÍÃìµÔ´µèÍ </strong>077-" .$row_show['MOBILE'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>àºÍÃìµÔ´µèÍ </strong>08" .$row_show['PHONE'] ;echo "</font>";
echo"<BR><BR>";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>ÃËÑʺѵûÃЪҪ¹</strong>" .$row_show['IDM'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>·ÕèÍÂÙè</strong>" ;echo "</font>";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ºéÒ¹àÅ¢·Õè</strong>" .$row_show['IDHOME'] ;echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ËÁÙè</strong>" . $row_show['MOO'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>«ÍÂ</strong>" .$row_show['ZOY'] ;echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>µÓºÅ</strong>" . $row_show['TUMBON'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>¶¹¹</strong>" .$row_show['ROAD']; echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ÍÓàÀÍ</strong>" .$row_show['ARUMPER'] ;echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>¨Ñ§ËÇÑ´</strong>" . $row_show['PROVINE'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ÃËÑÊä»ÃɳÕÂì</strong>" . $row_show['BOT'];echo "</font>";
echo"<BR><BR>";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ʶҹÐÀÒ¾</strong>" . $row_show['RASO'];echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>ºØ¤¤Å·ÕèÊÒÁÒöµÔ´µèÍ</strong>" .$row_show['TAITEL'] .$row_show['TNAME'];echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' >".$row_show['TUNAME'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>à¡ÕèÂÇ¢éͧà»ç¹</strong>" . $row_show['SO'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>àºÍÃìµÔ´µèÍ </strong>08".$row_show['MOBILE1'];echo "</font>";
echo" ";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>àºÍÃìµÔ´µèÍ </strong>077-".$row_show['PHONE1'];echo "</font>";
echo"<BR><BR>";
echo "<font size='2' face='MS Sans Serif' color='#000000' ><strong>ʶҹСÒÃÃѺàºÕéÂÂѧªÕ¾</strong>" .$row_show['YES'];echo "</font>";
echo" ";
echo " <font size='2' face='MS Sans Serif' color='#000000' ><strong>ÃٻẺ¡ÒÃÃѺà§Ô¹</strong>" . $row_show['MANNY'];echo "</font>";
echo"<BR><BR>";
echo" ";
echo"<BR><BR>";
echo "<a href='edit.php?edit_id=$row_show[id]' target='_blank' ><IMG SRC='images/postnews.gif' ALT='á¡éä¢' > </a>";echo "</font>";
echo" ";
echo "<a href='prin.php?edit_id=$row_show[id]' target='_blank' ><IMG SRC='images/printer.jpg' ALT='¾ÔÁ¾ì'> </a>";echo "</font>";
echo" ";
echo " <a href='delete.php?del_id=$row_show[id]' ><IMG SRC='images/delete.gif' ALT='ź' onClick='return Conf(this)');></a>";echo "</font>";
}
echo"</tr >";
echo"<table >";
//Êèǹ¹Õéà»ç¹¡ÒÃÊÃéÒ§äÎà»ÍÃìÅÔ§¤ìà¾×èÍãËé¼Ùéãªé¤ÅÔ¡´Ù¢éÍÁÙÅÊèǹ (˹éÒ) Í×è¹æ
?>
<br>
¤é¹¾º¢éÍÁÙÅ:<?= $Num_Rows;?> ÃÒ¡Òà <BR>àÅ×͡˹éÒ·Õè :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
mysql_close($objConnect);
}
?>
</CENTER><BR>
|
|
|
|
|
Date :
2010-07-06 12:25:57 |
By :
yesser |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**** ขอวิธีแก้ไข *****
- แก้ไขตรงรายละเอียดข้อมูลให้มันเรียงเป็นข้อๆทีละบรรทัดทำยังไง
แต่ฐานข้อมูลเวลาใส่มันเรียงเป็นข้อแล้วอยากให้ขึ้นโชว์เหมือนที่ใส่ไปคะ
ขอบคุณคะ
|
|
|
|
|
Date :
2017-04-17 16:50:28 |
By :
นักศึกษา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|