시소당
글쓴이 루슨 날 짜 07-05-17 10:06 조 회 1332
Link1 http://lucenhangul.com/wiki (72)
Link2 http://lucenhangul.com/wiki/?itemid=36 (100)
아래 올려봤던
・DB의 쿼리 값을 table로 간단하게 표시하는 클래스
를 PHP5로 해 봤습니다.
PHP5에서는 __construct와 __destruct를 사용할 수 있어 이전에 코멘트 아웃했던
・//
$this->TableFooter();
이 부분이 해결되었습니다.
------------------------------------------------------------------------------------------------
# 실행 부분
# db_query_display.php
<?php
include("dbinfo.inc");
require_once("query_list_display.class");
$Lucen = new QueryList;
$results =
$db->query("SELECT * FROM test");
while(
$rows =
$results->fetchRow()){
$Lucen->QueryListDisplay(
$rows);
}
?>
------------------------------------------------------------------------------------------------
# Class 정의
# query_list_display.class
<?php
class QueryList{
private
$thSwitch = true;
private function TableStyle(){
print<<<EOF
<style>
<!--
table {
border-collapse: collapse;
font-size: 12px;
}
table th, td{
border: 1px solid #CCCCCC;
line-height: 20px;
color: #666666;
padding-right: 10px;
padding-left: 10px;
}
-->
</style>\n
EOF;
}
function __construct(){
$this->TableStyle();
echo "<table>\n";
}
private function TableBody(
$query){
echo "<tr>";
foreach(
$query as
$key =>
$value){
if(
$this->thSwitch) echo "<th>".
$key."</th>";
$td_display .= "<td>".
$value."</td>";
}
if(
$this->thSwitch) echo "</tr><tr>\n";
echo
$td_display;
echo "</tr>\n";
$this->thSwitch = false;
}
function __destruct(){
echo "</table>\n";
}
function QueryListDisplay(
$query){
$this->TableBody(
$query);
}
}
?>
------------------------------------------------------------------------------------------------
출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=54042&sca=&sfl=wr_subject%7C%7Cwr_content&stx=php5&sop=and