|
 |
|
สอบถามการเรียงลำดับข้อมูลในฐานข้อมูลให้ซ้ำไปซ้ำมา (ตามตัวอย่าง) |
|
 |
|
|
 |
 |
|
ใช้ php ช่วยจะง่ายกว่าครับ
Code (PHP)
$rs_tb1=$db->query('select * from tb1');
$tb1 = array(); while($ro=$rs_tb1->fetch_assoc()) $tb1[]=$ro;
$rs_tb2=$db->qeury('select * from tb2');
$tb2 = array(); while($ro=$rs_tb2->fetch_assoc()) $tb2[]=$ro;
$start_time = strtotime('2015-12-15');
$th = 0; $en = 0;
echo '<table>';
for($i=0; $i<1000;$i++){
echo
'<tr>
<td>', date('Y-m-d', strtotime('+'.$i.' day', $strart_time)),'</td>
<td>', $tb1[$th]['fieldname'],'</td>
<td>', $tb2[$en]['fieldname'],'</td>
</tr>';
$th = ($th + 1) % count($tb1);
$en = ($en + 1 ) % count($tb2);
}
echo '</table>';
|
ประวัติการแก้ไข 2015-12-17 16:53:42
 |
 |
 |
 |
Date :
2015-12-17 16:50:39 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้ว ได้แบบนี้ครับ

ผมทำตามคำแนะนำด้านบน ครับ ช่วยอีกทีครับ มือใหม่
Code (PHP)
<html>
<head>
<title>xxxxxxxxxx</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("acting");
//$strSQL = "SELECT * FROM customer";
$rs_tb1=mysql_query('select * from practitioner');
$tb1 = array(); while($ro=$rs_tb1=mysql_fetch_assoc($rs_tb1)); $tb1[]=$ro;
$rs_tb2=mysql_query('select * from professional');
$tb2 = array(); while($ro=$rs_tb2=mysql_fetch_assoc($rs_tb2)); $tb2[]=$ro;
$start_time = strtotime('2015-12-15');
$th = 0; $en = 0;
echo '<table>';
for($i=0; $i<31;$i++){
echo
'<tr>
<td>', date('Y-m-d', strtotime('+'.$i.' day', $start_time)),'</td>
<td>', $tb1[$th]['Practitioner_Level_Name'],'</td>
<td>', $tb2[$en]['Professional_Level_Name'],'</td>
</tr>';
$th = ($th + 1) % count($tb1);
$en = ($en + 1 ) % count($tb2);
}
echo '</table>';
?>
</body>
</html>
ปล.ผมยังใช้ ไม่คล่องครับ
|
ประวัติการแก้ไข 2015-12-17 18:27:18
 |
 |
 |
 |
Date :
2015-12-17 18:26:21 |
By :
goolovestory |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองรอบ 2 ก็ยังไม่สำเร็จ มาแต่วันที่ครับ

Code (PHP)
<html>
<head>
<title>xxxxxxxxxx</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("acting");
//$strSQL = "SELECT * FROM customer";
$rs_tb1=mysql_query("select * from practitioner");
$tb1 = array(); while($ro=mysql_fetch_assoc($rs_tb1)); $tb1[]=$ro;
$rs_tb2=mysql_query("select * from professional");
$tb2 = array(); while($ro=mysql_fetch_assoc($rs_tb2)); $tb2[]=$ro;
$start_time = strtotime('2015-12-15');
$th = 0; $en = 0;
echo '<table>';
for($i=0; $i<31;$i++){
echo
'<tr>
<td>', date('Y-m-d', strtotime('+'.$i.' day', $start_time)),'</td>
<td>', $tb1[$th]['Practitioner_Level_Name'],'</td>
<td>', $tb2[$en]['Professional_Level_Name'],'</td>
</tr>';
$th = ($th + 1) % count($tb1);
$en = ($en + 1 ) % count($tb2);
}
echo '</table>';
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2015-12-17 18:36:18 |
By :
goolovestory |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
12.$tb1 = array(); while($ro=mysql_fetch_assoc($rs_tb1)); $tb1[]=$ro;
เอาสีแดงออกครับ อีกอันก็ด้วยครับ
รูปแบบเต็มเขาเป็นแบบนี้
12.$tb1 = array(); while($ro=mysql_fetch_assoc($rs_tb1)){ $tb1[]=$ro; }
เนื่องจากเป็นแค่คำสั่งเดียว ลดรูปลงเหลือ
12.$tb1 = array(); while($ro=mysql_fetch_assoc($rs_tb1)) $tb1[]=$ro;
|
 |
 |
 |
 |
Date :
2015-12-17 18:51:13 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณครับผม

ถ้าผมจะสลับสีตาราง ต้องใส่ Code PHP ตรงไหนครับ
|
ประวัติการแก้ไข 2015-12-17 20:52:54
 |
 |
 |
 |
Date :
2015-12-17 20:52:23 |
By :
goolovestory |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สลับสีคือ คู่คี่ ใช้ ($i % 2)
$color=array('red','blue');
echo "<tr bgcolor='$color[$i % 2]'>";
|
 |
 |
 |
 |
Date :
2015-12-17 21:12:54 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|