Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ต้องการให้สินค้ามันเป็นสองแถวแล้วก็ตัดหน้าให้มันเปน หน้า 1,2,3, พอมีวิธีไหมค่ะ



 

ต้องการให้สินค้ามันเป็นสองแถวแล้วก็ตัดหน้าให้มันเปน หน้า 1,2,3, พอมีวิธีไหมค่ะ

 



Topic : 109311



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์




ต้องการให้สินค้ามันเป็นสองแถวแล้วก็ตัดหน้าให้มันเปน หน้า 1,2,3, พอมีวิธีไหมค่ะ


ตัวอย่าง



Tag : PHP, CakePHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-06-19 14:51:22 By : zerza18 View : 1029 Reply : 5
 

 

No. 1



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์


ส่วนนี้โค้ดค่ะ



<?
$id_type_select=$_GET[type_id];
include "connect.php";
?>
<?
session_start();
if($_SESSION['UserID'] == "")
{
echo "Please Login!";
exit();
}

include "connect.php";
$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {color: #FF0066}
.style2 {color: #FF0033}
-->
</style>
</head>
<body Onload="doAddCart('','','')">
<div class="main">
<div class="search"></div>
<div class="clr"></div>
<div class="header">
<div class="logo">
<h1><span class="style1"> Banhom Shop Online </span></h1>
</div>
<table border="0" align="right" style="width: 300px">
<tbody>
<tr>
<td width="87" align="right"><a href="edit_profile.php">แก้ไขข้อมูลส่วนตัว</a></td>

</tr>
<tr>
<td align="right"><a href="logout.php">ออกจากระบบ</a></td>

</tr>
</tbody>
</table>
<div class="menu_nav">
<ul>
<li class="active"><a href="index.php">หน้าแรก</a></li>

<li><a href="How to order.php">วิธีการสั่งซื้อ</a></li>
<li><a href="How to payment.php">วิธีการชำระเงิน</a></li>
<li><a href="payment.php">แจ้งชำระเงิน</a></li>
<li><a href="login.php">เข้าสู่ระบบ</a></li>
<li><a href="Webbord.php">เว็บบอร์ด</a></li>
<li><a href="contact.php">ติดต่อเรา</a></li>
</ul>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
<div class="hbg">
<div align="center"><img src="image/logoo.jpg" width="967" height="300" alt="" /></div>
</div>
<div class="content">

<div class="content">
<table width="850" border="0" cellpadding="10">
<tr>
<td width="250"><h1>&nbsp;</h1></td>
<td width="550">&nbsp;</td>
</tr>
<tr>
<td align="center" valign="top"><p><img src="image/type.jpg" width="240" height="40" /><br>
<?
include "connect.php";
include "type_menu.php";
?>
</p></td>
<td width="550"><table width="450" border="0" align="center" cellpadding="15">
<?

$strSQL = "SELECT * FROM product where type_id='$id_type_select'";

$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 6; // 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;
}
if ($id_typee==""){
$strSQL ="select * from product order by product_id desc LIMIT $Page_Start , $Per_Page";
}else{
$strSQL ="select * from product where type_id='$id_typee' order by product_id desc LIMIT $Page_Start , $Per_Page";
}
mysql_query("SET NAMES UTF8 ");
$objQuery = mysql_query($strSQL);
while ($rs=mysql_fetch_array($objQuery)) {
?>
<tr>
<td width="100" valign="top"><img src="images/<?=$rs[product_image]?>" alt="" width="100" /></td>
<td><?
$product_id = $rs[product_id];
$code = sprintf($product_id );
?>
<b> รหัสสินค้า : </b>
<?=$code?>
<br />
<b> ชื่อสินค้า : </b>
<?=$rs[product_name]?>
<br />
<b> ราคา : </b>
<?=$rs[product_price]?>
บาท<br />
<br />
<a href="basket_add.php?id=<?=$rs[product_id]?>"><img src="image/bl_shopping.gif" width="98" height="21" /></a></td>
</tr>
<?
}
?>

</table>
<p><br>
<table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td ><div align="center">รวมจำนวน
<?= $Num_Rows;?>
รายการ :
<?=$Num_Pages;?>
หน้า :
<?
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&id_typee=$id_typee'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&id_typee=$id_typee'>Next>></a>";
}
mysql_close();
?>
<br />
<br />
</div></td>
</tr>
</table>
<br></td>
</tr>
</table>
</a>
</td>
</tr>

</table>&nbsp;</p></td>
</tr>
</table>
<p>&nbsp;</p>
</div>

</div></p>
</div>
</div>
</div>
</div>
<div class="footer">
<div align="center"><img src="image/end.gif" width="930" height="222" alt=""/></div>
</div>
</div>
<div align=center></div>
</body>
</html>






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-19 14:54:26 By : zerza18
 


 

No. 2



โพสกระทู้ ( 1,666 )
บทความ ( 0 )



สถานะออฟไลน์


ส่วนตัดหน้าถูกแล้วนะครับหน้าละ 6 ชิ้น
  $Per_Page = 6; // Per Page  

*ลองใส่ สินค้าไปซัก 7 เดี๋ยวจะมีหน้าสองตามมาแน่ๆ


ส่วน ทำ 2 แถว ก็ต้องให้ 1 TR มี 2 TD ประมาณนี้มั้ง
**ไม่รู้จะบอกยังไงดี ไม่มีบรรทัดให้บอก ทีหลังกดปุ่ม PHP CODE ด้านบนก่อนลงโค้ดนะครับเพื่อความสะดวกในการอ่าน


Code (PHP)
mysql_query("SET NAMES UTF8 ");
$objQuery = mysql_query($strSQL); 
$xxx=0; //เพิ่มเข้ามา
while ($rs=mysql_fetch_array($objQuery)) {
if ($xxx%2==0) { echo "<tr>"; } 
//ถ้า $xxx หาร2เศษ0 ก็สั่งเปิด tr
?>
<td width="100" valign="top"><img src="images/<?=$rs[product_image]?>" alt="" width="100" /></td>
<td><?
$product_id = $rs[product_id];
$code = sprintf($product_id );
?>
<b> รหัสสินค้า : </b>
<?=$code?>
<br />
<b> ชื่อสินค้า : </b>
<?=$rs[product_name]?>
<br />
<b> ราคา : </b>
<?=$rs[product_price]?>
บาท<br />
<br /> 
<a href="basket_add.php?id=<?=$rs[product_id]?>"><img src="image/bl_shopping.gif" width="98" height="21" /></a></td>

<?
$xxx++;  //สั่ง xxx +1 
}
?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-19 15:17:51 By : meannerss
 

 

No. 3



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์


นี้ค่ะโค้ดลงใหม่แล้วค่ะ ลงสินค้าไป 10 แล้วน่ะค่ะแต่ทำไมมันไม่มีหน้า 2 3 ตามมาค่ะ


Code (PHP)
<?
$id_type_select=$_GET[type_id];
include "connect.php";
?>
<?
	session_start();
	if($_SESSION['UserID'] == "")
	{
		echo "Please Login!";
		exit();
	}
 
	include "connect.php";
	$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {color: #FF0066}
.style2 {color: #FF0033}
-->
</style>
</head>
<body Onload="doAddCart('','','')">
<div class="main">
  <div class="search"></div>
  <div class="clr"></div>
  <div class="header">
    <div class="logo">
      <h1><span class="style1"> Banhom Shop Online </span></h1>
    </div>
      <table border="0" align="right" style="width: 300px">
                            <tbody>
                               <tr>
                                <td width="87" align="right"><a href="edit_profile.php">แก้ไขข้อมูลส่วนตัว</a></td>
                                                         
                              </tr>
                              <tr>
                                <td align="right"><a href="logout.php">ออกจากระบบ</a></td>
                                                         
                              </tr>
                            </tbody>
                          </table>
    <div class="menu_nav">
      <ul>
        <li class="active"><a href="index.php">หน้าแรก</a></li>
      
          <li><a href="How to order.php">วิธีการสั่งซื้อ</a></li>
           <li><a href="How to payment.php">วิธีการชำระเงิน</a></li>
          <li><a href="payment.php">แจ้งชำระเงิน</a></li>
          <li><a href="login.php">เข้าสู่ระบบ</a></li>
          <li><a href="Webbord.php">เว็บบอร์ด</a></li>
        <li><a href="contact.php">ติดต่อเรา</a></li>
      </ul>
      <div class="clr"></div>
    </div>
    <div class="clr"></div>
  </div>
  <div class="hbg">
    <div align="center"><img src="image/logoo.jpg" width="967" height="300" alt="" /></div>
  </div>
  <div class="content">
   
  <div class="content">
    <table width="850" border="0" cellpadding="10">
      <tr>
        <td width="250"><h1>&nbsp;</h1></td>
        <td width="550">&nbsp;</td>
      </tr>
      <tr>
        <td align="center" valign="top"><p><img src="image/type.jpg" width="240" height="40" /><br>       
          <?
include "connect.php";
include "type_menu.php";
?>
        </p></td>
        <td width="550"><table width="450" border="0" align="center" cellpadding="15">
          <?

 $strSQL = "SELECT * FROM product  where type_id='$id_type_select'";

$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); 
$Num_Rows = mysql_num_rows($objQuery); 
$Per_Page = 6;   // 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; 
} 
if ($id_typee==""){
  $strSQL ="select * from product order  by product_id desc LIMIT $Page_Start , $Per_Page"; 
  }else{
    $strSQL ="select * from product where type_id='$id_typee' order  by product_id desc LIMIT $Page_Start , $Per_Page"; 
  } 
 mysql_query("SET NAMES UTF8 ");
$objQuery  = mysql_query($strSQL); 
while ($rs=mysql_fetch_array($objQuery)) {
?>
          <tr>
            <td width="100" valign="top"><img src="images/<?=$rs[product_image]?>" alt="" width="100" /></td>
            <td><?
$product_id = $rs[product_id];
$code = sprintf($product_id );
?>
              <b> รหัสสินค้า : </b>
              <?=$code?>
              <br />
              <b> ชื่อสินค้า : </b>
              <?=$rs[product_name]?>
              <br />
              <b> ราคา : </b>
              <?=$rs[product_price]?>
              บาท<br />
              <br />              
              <a href="basket_add.php?id=<?=$rs[product_id]?>"><img src="image/bl_shopping.gif" width="98" height="21" /></a></td>
          </tr>
          <?
}
?>

        </table>
          <p><br>
          <table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td ><div align="center">รวมจำนวน
                <?= $Num_Rows;?>
                รายการ :
                <?=$Num_Pages;?>
                หน้า :
                <? 
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&id_typee=$id_typee'>$i</a> ]";
} 
else
{ 
echo "<b> $i </b>"; 
} 
} 
if($Page!=$Num_Pages) 
{ 
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&id_typee=$id_typee'>Next>></a>";
} 
mysql_close(); 
?>
                <br />
                <br />
              </div></td>
            </tr>
          </table>
          <br></td>
        </tr>
      </table>
</a> 
	  </td>
  </tr>
  
</table>&nbsp;</p></td>
      </tr>
    </table>
    <p>&nbsp;</p>
  </div>

</div></p>
</div>
      </div>
</div>
  </div>
 <div class="footer">
    <div align="center"><img src="image/end.gif" width="930" height="222"  alt=""/></div>
  </div>
</div>
<div align=center></div>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-19 15:44:47 By : zerza18
 


 

No. 4



โพสกระทู้ ( 1,666 )
บทความ ( 0 )



สถานะออฟไลน์


บรรทัด 114 if ($id_typee==""){

ตัวแปร $id_typee ไม่ได้มีการประกาศ/รับค่าอะไรไว้เลยนะครับ
** id_typee นี่น่าจะมาจาก $_GET ไช่ไหมครับ


ลองแบบนีดู ลบบรรทัด 114 ออกแล้วใส่นี่ลงไปแทน
if($_GET['id_typee']) { $id_typee= $_GET['id_typee']; } else {  $id_typee="";  }
if ($id_typee==""){

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-19 16:34:10 By : meannerss
 


 

No. 5



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ตัวอยาง การคำนวณ แสดง บางส่วน ของ table
yourhost?perpage=10&cur_page=1&etc=......


Code (PHP)
////////////////////////////////////////////////////////////////////////////////
function row_count($table, $fldName){
	$qr='select count('.$fldName.') c from '.$table;
	$rs=mysql_query($qr);
	if(mysql_errno()) return false;
	$ro=mysql_fetch_assoc($rs); mysql_free_result($rs);
	return $ro['c'];
}
////////////////////////////////////////////////////////////////////////////////
if(isset($_REQUEST['search_text'])){
	$where=" tb_1 where concat(detail, topic) LIKE '%$_REQUEST[search_text]%' ";
}else{
	$where=" tb_1 ";
}
//  กำหนด จำนวน ต่อหน้า
$per_page=isset($_REQUEST['per_page'])? $_REQUEST['per_page'] : 20;
// หาจำนวน เรคคอร์ดทั้งหมด
$rowCount=row_count($where, 'id');
// หาจำนวน หน้าทั้งหมด
$pageCount=page_no($rowCount, $per_page);
// กำหนด หน้าปัจจุบัน 
$curPage=isset($_REQUEST['cur_page'])? $_REQUEST['cur_page'] : 0;

// กำหนด แสดงหมายเลขหน้า ปัจจุบัน บน HTML
$show_curPage=$curPage+1;
// กำหนด Link แสดงหมายเลขหน้า ย้อนหลัง บน HTML
$link_prior_page=$curPage? $curPage-1 : '';
// กำหนด Link แสดงหมายเลขหน้า หน้าต่อไป บน HTML
$link_next_page=($pageCount-$curPage)>1? $curPage+1 : '';

////////////////////////////////////////////////////////////////
// คำสั่งเลือก แสดงบาง records อยู่ที่ limit เร่ิม , จำนวน row ที่แสดง
$rs=mysql_query('select * from '.$where.' order by id desc limit '.($curPage*$per_page).','.$per_page);
$num_row=mysql_num_rows($rs); $bc=false;
if($num_row){
	while($ro=mysql_fetch_assoc($rs)){
		// echo your need
	}
}
mysql_free_result($rs);
mysql_close();



ประวัติการแก้ไข
2014-06-19 17:00:22
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-19 16:51:22 By : Chaidhanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการให้สินค้ามันเป็นสองแถวแล้วก็ตัดหน้าให้มันเปน หน้า 1,2,3, พอมีวิธีไหมค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่