|
 |
|
สอบถามเรื่องการสร้างตารางสินค้าหน่อยครับ คิดอัลกอลิทึมไม่ถูกครับ |
|
 |
|
|
 |
 |
|
ทำรูปมาให้ดูหน่อยครับ
4 ตาราง ขึ้นใหม่เป็นอย่างไร นึกภาพไม่ออก 
|
 |
 |
 |
 |
Date :
2014-04-24 19:12:57 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ประมาณว่า
Code (PHP)
<table>
<tr>
<td>สินค้าชิ้นที่1</td>
<td>สินค้าชิ้นที่2</td>
<td>สินค้าชิ้นที่3</td>
<td>สินค้าชิ้นที่4</td>
</tr>
</table>
ยังงี้น่ะครับ ถ้ามีสินค้าชิ้นที่ 5 เข้ามา ก็จะเริ่ม <tr><td></td></tr> ใหม่ ประมาณนี้
|
ประวัติการแก้ไข 2014-04-24 21:05:52 2014-04-24 21:06:29
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<form id="rx" name="x" class="rx" >
<?php
require 'mysql.php'; //เรียก Class : MySQL_Connection นำมาจาก https://www.thaicreate.com/community/php-mysql-connection-class.html
/*ถ้าไม่ได้ใช้คลาสตัวนี้ ก็ต้องปรับ คำสั่ง mysql ด้วยครับ*/
include 'config.php'; //เรียกไฟล์ติดต่อฐานข้อมูล
$mysql=new MySQL_Connection("$host","$user","$pw","$dbname");
$mysql->charset = 'utf8';
/*ขั้นแรก หาจำนวน record ทั้งหมดออกมาก่อน*/
$sql ="SELECT * FROM tb_product";
$mysql->query($sql);
$result = $mysql->queryResult($sql);
$total =$result->numRows;
echo 'จำนวน Record : '.$total."<br><br>";
//พวกชื่อตัวแปรทั้งหลายคุณก็ไปปรับเอาตามความเหมาะสม//
$Per_Page = 4; //กำหนดให้ตารางมีแค่ 4 แถว
$Page=1;
$Num_Pages = ceil($total/$Per_Page) ; //หาจำนวนตารางทั้งหมด
echo 'ตารางทั้งหมด : '.$Num_Pages."<br><br>";
//นำค่าตารางมาวนลูปเพื่อทำการคิวรี่ข้อมูลตามต้องการ
for($i=0;$i<$Num_Pages; $i++){
//แสดงตัวแปรกันพลาด รีเช็ค
$Page_Start = (($Per_Page*$Page)-$Per_Page);
echo '$Page_Start : '.$Page_Start."<br>";
echo '$Per_Page : '.$Per_Page."<br>";
echo '$Page : '.$Page."<br>";
echo '$i : '.$i."<br><br>";
$Page++;
$sql2 ="SELECT * FROM tb_product order by tb_product .id ASC LIMIT $Page_Start , $Per_Page";
$mysql->query($sql2);
$result2 = $mysql->queryResult($sql2);
?>
<h6>แสดงสินค้า</h6>
<table id="gradient-style">
<thead>
<tr>
<th scope="col">ลำดับที่</th>
<th scope="col">ชื่อสินค้า</th>
<th scope="col">ประเภทสินค้า</th>
<th scope="col">ราคา</th>
</tr>
</thead>
<tbody>
<?php
while($rs = $result2->fetch()){
?>
<tr>
<td><?php echo $rs['id'];?></td>
<td><?=$rs['product_name']?></td>
<td><?php echo $rs['product_type'];?></td>
<td><?php echo $rs['product_cost'];?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<? } ?>
</form>
//ที่เหลือต้องไปประยุกต์เอง อย่างที่บอกไม่เห็น db ก็ช่วยไรไม่ได้มาก
ไอ้ครั้นจะทำแบบที่บอก
Code (PHP)
<table>
<tr>
<td>สินค้าชิ้นที่1</td>
<td>สินค้าชิ้นที่2</td>
<td>สินค้าชิ้นที่3</td>
<td>สินค้าชิ้นที่4</td>
</tr>
</table>
- ถ้าจะจัดเรียงเอาเฉพาะชื่อสินค้ามาแสดง ก็ลองไปปรับดูครับ
|
ประวัติการแก้ไข 2014-04-25 10:28:09
 |
 |
 |
 |
Date :
2014-04-25 10:27:06 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<table>
<tr>
$i=0
while(fetch){
if($i=4){
echo </tr><tr>
$i=0
}
<td>echo สินค้า</td>
$i++
}
</tr>
</table>
|
 |
 |
 |
 |
Date :
2014-04-25 11:14:50 |
By :
natt_han |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทั้งสองท่านครับ ตอนนี้ทำได้แล้วครับ ใช้วิธีของคุณ
natt_han
เลยครับ ^^
|
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|