|
|
|
อยากจะ select ตารางแบ่งออกเป็นคอลัมน์ และแยกเป็นกลุ่มๆ แบบตัวอย่างรูปภาพค่ะ |
|
|
|
|
|
|
|
แนวทางนะครับ
Code (PHP)
<?
$SQL = "select distinct depart from phone_list order by id";
$QRY = mysql_db_query($dbname, $SQL);
$a=0;
while($RS = mysql_fetch_object($QRY)){
$depart = $RS -> depart;
$a++;
echo ".$a.". ".$depart."</b>";
$phoneSQL = "select * from phone_list where depart='".$depart."' order by id";
$phoneQRY = mysql_db_query($dbname, $phoneSQL);
$rows = mysql_num_rows($phoneQRY );
$pagesize = 20;
if($page == "") {
$start = 0;
$page = 1;
} else {
$start=$pagesize*($page-1);
}
$Prev = $page-1;
$Next = $page+1;
$Numpage = (int)($rows/$pagesize);
if(($rows%$pagesize) != 0) {
$Numpage = $Numpage + 1;
}
$phoneQRY = mysql_db_query($dbname, $phoneSQL ." limit $start,$pagesize");
$cols = 2;
$c = $cols;
$p=$start;
?>
<br>
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
<tr >
<?
while($phoneRS = mysql_fetch_object($phoneQRY)){
$id = $phoneRS -> id;
$depart = $phoneRS -> depart;
$name_eng = $phoneRS -> name_eng;
$name_thai = $phoneRS -> name_thai;
$tell = $phoneRS -> tell;
$class_work = $phoneRS -> class_work;
$c--;
$p++;
?>
<td width="50%" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'">
<?
echo "".$name_eng."";
?></td>
<td width="50%" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'"><?
echo "".$name_thai."";
?></td>
<td width="50%" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'"><?
echo "".$tell."";
?></td>
<? if($c == 0) { $c = $cols; ?>
</tr>
<? } } ?>
</table></div>
<?
}
?>
|
|
|
|
|
Date :
2014-11-12 12:47:02 |
By :
LAGO |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากๆค่ะ คุณ LAGO
เราจะกำหนดแถว row อย่างไงหรอค่ะ ให้เริ่มตารางขึ้นใหม่จากทางด้านขวา เนื่องจากข้อมูลมันต่อท้ายกันมา ค่ะ
ตัวอย่างจากรูปภาพ
Code (PHP)
<?
session_start();
header ('Content-type: text/html; private; charset=utf-8');
ob_start();
require_once "include/connect.php";
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?
$SQL = "select distinct depart from employee order by eid";
$QRY = mysql_db_query($db, $SQL);
$a=0;
while($RS = mysql_fetch_object($QRY)){
$depart = $RS -> depart;
$a++;
echo
"<table width='500' border='1' cellpadding='0' cellspacing='0' bgcolor='#f9f2c3'>
<tr>
<td height='25'><font size='2'><strong> $depart</strong></font></td>
</tr>
</table>";
?>
<?
$phoneSQL = "select * from employee where depart='".$depart."' order by eid";
$phoneQRY = mysql_db_query($db, $phoneSQL);
$rows = mysql_num_rows($phoneQRY );
$pagesize = 30;
if($page == "") {
$start = 0;
$page = 1;
} else {
$start=$pagesize*($page-1);
}
$Prev = $page-1;
$Next = $page+1;
$Numpage = (int)($rows/$pagesize);
if(($rows%$pagesize) != 0) {
$Numpage = $Numpage + 1;
}
$phoneQRY = mysql_db_query($db, $phoneSQL ." limit $start,$pagesize");
$cols = 2;
$c = $cols;
$p=$start;
?>
<table width="500" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC">
<tr >
<?
while($phoneRS = mysql_fetch_object($phoneQRY)){
$id = $phoneRS -> id;
$depart = $phoneRS -> depart;
$name_eng = $phoneRS -> name_eng;
$name_thai = $phoneRS -> name_thai;
$tell = $phoneRS -> tell;
$class_work = $phoneRS -> class_work;
$c--;
$p++;
?>
<td width="200" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'">
<font size="2"><?=$name_eng;?></font>
</td>
<td width="160
" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'">
<font size="2"><?=$name_thai;?></font>
</td>
<td width="0" valign="top" bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'">
<font size="2"><?=$tell;?></font>
</td>
</tr>
<? } ?>
</table>
<?
}
?>
</body>
</html>
|
ประวัติการแก้ไข 2014-11-12 16:31:34
|
|
|
|
Date :
2014-11-12 16:25:27 |
By :
loomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กำหนด ตัวแปร เป็น array ช่วย ครับ
Code (PHP)
$column = array('', '');
$i=0; $col=0;
while($ro=$rs->fetch_assoc()){
$column[$col] .= $ro; // ตรงนี้ ไปจัดการเอาเองนะครับ แค่ตัวอย่าง
$i++;
if($i==30){
$col++;
if($col=2){
echo "<tr><td>$column[0]</td><td>$column[1]</td></tr>";
$col=0; $column=array('', '');
}
$i=0;
}
}
if($i>0){
echo "<tr><td>$column[0]</td><td>$column[1]</td></tr>";
}
|
|
|
|
|
Date :
2014-11-12 16:53:13 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|