|
 |
|
ดึงข้อมูลจากฐานข้อมูล อยากให้ดึงแบบว่าสมมุติข้อมูลมีทั้งหมด 10 ข้อมูล ให้ทำการแสดงแถวละ |
|
 |
|
|
 |
 |
|
อยากให้ดึงแบบว่า
สมมุติข้อมูลมีทั้งหมด 10 ข้อมูล ให้ทำการแสดงแถวละ 4 ข้อมูลแล้วข้อมูลที่ 5-8 ลงมาแถวที่ 2
ข้อมูลที่ 9-10 แถวที่ สาม ครับ

Code (PHP)
<?
include"includes/conn.php";
$sql = "select * from buy";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
echo "<br><br><br><table align='center' width='80%'>";
for($i=0;$i<$count;$i++){
$id = mysql_result($result,$i,"id");
$img = mysql_result($result,$i,"img");
$detail = mysql_result($result,$i,"detail");
$c_male = mysql_result($result,$i,"c_male");
$c_female = mysql_result($result,$i,"c_female");
$p_male = mysql_result($result,$i,"p_male");
$p_female = mysql_result($result,$i,"p_female");
$address = mysql_result($result,$i,"address");
$specie = mysql_result($result,$i,"specie");
if($i >=0 and $i <4){
echo "<td><center><a href='order.php?id=$id'><img src='img/$img' width='200' height='200' border=0></a></center><br><br>";
echo "สายพันธ์ $specie<br>";
echo "$detail<br>";
echo "เพศผู้ $c_male ตัว ราคาตัวละ $p_male บาท<br>";
echo "เพศเมีย $c_female ตัว ราคาตัวละ $p_female บาท<br>";
echo "ที่อยู่ $address<br><br><br>";
echo "</td>";
}else if($i >=4 and $i <8){
echo "<td><center><a href='order.php?id=$id'><img src='img/$img' width='200' height='200' border=0></a></center><br><br>";
echo "สายพันธ์ $specie<br>";
echo "$detail<br>";
echo "เพศผู้ $c_male ตัว ราคาตัวละ $p_male บาท<br>";
echo "เพศเมีย $c_female ตัว ราคาตัวละ $p_female บาท<br>";
echo "ที่อยู่ $address<br><br><br>";
echo "</td>";
}
}
echo "</table>";
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-03-10 23:32:52 |
By :
tonnant |
View :
1064 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาแบบง่ายๆ นะ
Code (PHP)
<table cellpadding=0 cellspacing=2 border=0 width=650>
<tr>
<?php
$i=1;
while ($row=mysql_fetch_array($result)) {
$id=$row['id'];
$img=$row['img'];
$specie=$row['specie'];
$detail=$row['detail'];
?>
<td valign=top>
<?php echo "<a href='order.php?id=$id'><img src='img/$img' width='200' height='200' border=0></a><br>";
echo "สายพันธ์ $specie<br>";
echo "$detail<br>";
?>
</td>
<?php
if ($i%4==0) {echo "</tr>";}
$i++;
}?>
</table>
|
 |
 |
 |
 |
Date :
2010-03-10 23:48:02 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ ขอลองเอาไปเทสดูหน่อยนะครับ
ยังไงก็ ขอบคุณมากๆๆๆๆๆๆครับ
|
 |
 |
 |
 |
Date :
2010-03-11 00:04:39 |
By :
tonnant |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|