묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
"pass" => "비번",
"db" => "DB명",
"table" => "xe_documents",
특정 게시판 리스트,확장변수를 엑셀파일로 출력하는 방법 없나요?
2013.02.05 17:02
게시판을 클릭했을 때 목록 list 보여지고 있는 항목을 가져오고 싶은데 ...
아래처럼 하면 확장변수 ID 값을 표기 못하는데 ,표기 하는 방법없을까요?
<?php
$info = array(
"host" => "호스트",
"user" => "아이디","pass" => "비번",
"db" => "DB명",
"table" => "xe_documents",
"module_srl" => "게시판모듈번호",
);
$getFields = array("title","nick_name","regdate"); //출력원하는 칼럼을 배열로 입력
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=documents.xls");
$con = mysql_connect($info[host], $info[user], $info[pass]) || die(mysql_error());
mysql_query("set names utf8");
$con_db = mysql_select_db($info[db]) || die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=Content-Type content=text/html; charset="utf-8">
</head>
<body>
<table border=1>
<tr align=center>
<?php
$fields = mysql_list_fields("$info[db]", "$info[table]");
$columns = mysql_num_fields($fields);
for( $i=0 ; $i<$columns ; $i++ )
{
$field[$i]=mysql_field_name($fields, $i);
if( in_array($field[$i], $getFields) ) echo "<th>".$field[$i]."</th>";
}
?>
</tr>
<?php
$result = mysql_query("select * from $info[table] where module_srl = $info[module_srl]");
while( $data = mysql_fetch_assoc($result) )
{
echo"<tr>";
foreach( $data as $key => $val )
{
if( in_array($key, $getFields) ) echo "<td>".htmlspecialchars($val)."</td>";
}
echo"</tr>";
}
?>
</table>
</body>
</html>
아래 처럼 하면 확장변수 값은 가져 올수 잇는데 두개를 혼합해서 리스트하고 확장변수값 보여주게 하고싶어요...
<?
$connect_host
=
"localhost"
;
$connect_id
=
"@@"
;
$connect_pass
=
"@@"
;
$connect_db
=
"@@"
;
$connect_table
=
"xe_document_extra_vars"
;
$xls_filename
=
"@@.xls"
;
$connect
=@mysql_connect(
$connect_host
,
$connect_id
,
$connect_pass
);
@mysql_query(
"set character set utf8"
);
// 한글 입출력 문제 해결을 위해..
$mysql
=@mysql_select_db(
$connect_db
,
$connect
);
header(
"Content-Type: application/vnd.ms-excel"
);
header(
"Content-Disposition: attachment; filename=$xls_filename"
);
?>
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=utf-8>
<meta http-equiv=Content-Type content=text/html; charset=EUC-KR>
</head>
<body leftmargin=
"0"
marginwidth=
"0"
topmargin=
"0"
marginheight=
"0"
>
<table border=
"1"
cellspacing=
"0"
cellpadding=
"0"
style=
"border-collapse: collapse"
>
<tr align=center>
<?
$fields
= mysql_list_fields(
"$connect_db"
,
"$connect_table"
);
$columns
= mysql_num_fields(
$fields
);
for
(
$i
= 0;
$i
<
$columns
;
$i
++) {
$field
[
$i
]=mysql_field_name(
$fields
,
$i
);
}
?>
<tr>
<td>항목A</td>
<td>항목B</td>
<td>항목C</td>
<td>항목D</td>
<td>항목E</td>
<td>항목F</td>
<td>항목G</td>
</tr>
<?
/*$result=mysql_query("select * from $connect_table");*/
$result
=mysql_query(
"select * from $connect_table where module_srl=281 order by document_srl, var_idx"
);
$ctmp
= 1;
echo
"<tr>"
;
while
(
$data
=mysql_fetch_assoc(
$result
)){
for
(
$i
= 4;
$i
< sizeof(
$field
);
$i
=
$i
+5) {
echo
"<td><span style='FONT-FAMILY:tahoma; FONT-SIZE:8pt;'>"
.
$data
[
"$field[$i]"
].
"</td>"
;
if
(
$ctmp
%7 == 0)
// 확장변수 수만큼 값을 넣으세요.
{
echo
"</tr>"
;
if
(
$i
+5<sizeof(
$field
)){
echo
"<tr>"
;
}
}
$ctmp
=
$ctmp
+ 1;
}
}
?>
</table>
</body>
</html>