특정 그룹및 게시판 불러 오고 싶습니다.

안녕하세요!
자기 자신이 쓴글 목록 추출 할려고 하는데요,
전체 추출이 아닌. 특정 그룹 및 특정 게시판만 불러 오고 싶습니다...
방법좀 알려주세요.


if ($member[mb_id])
{
    $new_count = 10;

    $cnt = 0;
    $sql = " select bo_table, wr_parent from $g4[board_new_table] a
              where mb_id = '$member[mb_id]'
                -- and a.wr_id = a.wr_parent
                group by bo_table, wr_parent
                order by bn_id desc
                limit $new_count ";
    $res = sql_query($sql);

    echo "<table width=500 cellpadding=0 cellspacing=0>";

    for ($i=0; $row=sql_fetch_array($res), $i<$new_count; $i++)
    {
        if (!$row[bo_table])
        {
            continue;
        }

        $tmp_table = $g4[write_prefix].$row[bo_table];
        $sql2 = " select wr_subject, wr_comment from $tmp_table where wr_id = '$row[wr_parent]' ";
        $row2 = sql_fetch($sql2);
        $subj = get_text($row2[wr_subject]);
        $comment = "";
        if ($row2[wr_comment])
            $comment = "<span class=small>($row2[wr_comment])</span>";
        echo "<tr><td class=bg_menu2 title='$subj'>";
        echo "<nobr style='display:block;overflow:hidden;width:400px;'>";
        echo "<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row[wr_parent]'>";
        echo "<span style='color:#438A01;'>$comment $subj</span></a>";
        echo "</nobr></td></tr>";

|

댓글 7개

소스 전체를 볼수 없어 정확한 지 모르겠지만 이렇게 한 번 해 보세요!
상단의 sql문을 아래로 변경해서 테스트 해보세요.

$sql = " select bo_table, wr_parent from $g4[board_new_table]
where mb_id = '$member[mb_id]'
group by bo_table
order by bn_id desc
limit $new_count ";

$res = sql_query($sql);
ohora님.. 답변 감사합니다. 답변채택못해 드려서 대단히 죄송합니다.
특정 그룹에서만 불러올 경우

if ($member[mb_id])
{
$new_count = 10;
$tmp_gr_id = "불러올 그룹명";
$cnt = 0;

$sql_group = " select bo_table from $g4[board_table] where gr_id = '$tmp_gr_id' ";
$tmp_bo_table_array = sql_query($sql_group);

$sql = " select bo_table, wr_parent from $g4[board_new_table] a
where mb_id = '$member[mb_id]'
-- and a.wr_id = a.wr_parent
and bo_table in " . $tmp_bo_table_array . "
group by bo_table, wr_parent
order by bn_id desc
limit $new_count ";
$res = sql_query($sql);

echo "<table width=500 cellpadding=0 cellspacing=0>";

for ($i=0; $row=sql_fetch_array($res), $i<$new_count; $i++)
{
if (!$row[bo_table])
{
continue;
}

$tmp_table = $g4[write_prefix].$row[bo_table];
$sql2 = " select wr_subject, wr_comment from $tmp_table where wr_id = '$row[wr_parent]' ";
$row2 = sql_fetch($sql2);
$subj = get_text($row2[wr_subject]);
$comment = "";
if ($row2[wr_comment])
$comment = "<span class=small>($row2[wr_comment])</span>";
echo "<tr><td class=bg_menu2 title='$subj'>";
echo "<nobr style='display:block;overflow:hidden;width:400px;'>";
echo "<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row[wr_parent]'>";
echo "<span style='color:#438A01;'>$comment $subj</span></a>";
echo "</nobr></td></tr>";


특정 게시판에서만 불러올 경우

if ($member[mb_id])
{
$new_count = 10;

$tmp_bo_table_array = "('게시판1', '게시판2', '게시판3', '게시판4')";

$cnt = 0;
$sql = " select bo_table, wr_parent from $g4[board_new_table] a
where mb_id = '$member[mb_id]'
-- and a.wr_id = a.wr_parent
and bo_table in " . $tmp_bo_table_array . "
group by bo_table, wr_parent
order by bn_id desc
limit $new_count ";
$res = sql_query($sql);

echo "<table width=500 cellpadding=0 cellspacing=0>";

for ($i=0; $row=sql_fetch_array($res), $i<$new_count; $i++)
{
if (!$row[bo_table])
{
continue;
}

$tmp_table = $g4[write_prefix].$row[bo_table];
$sql2 = " select wr_subject, wr_comment from $tmp_table where wr_id = '$row[wr_parent]' ";
$row2 = sql_fetch($sql2);
$subj = get_text($row2[wr_subject]);
$comment = "";
if ($row2[wr_comment])
$comment = "<span class=small>($row2[wr_comment])</span>";
echo "<tr><td class=bg_menu2 title='$subj'>";
echo "<nobr style='display:block;overflow:hidden;width:400px;'>";
echo "<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row[wr_parent]'>";
echo "<span style='color:#438A01;'>$comment $subj</span></a>";
echo "</nobr></td></tr>";
앵무나라님.. 답변 감사합니다. 그런데 적용 했는데.
아래 처럼 에러가 뜨는데... 좀 봐 주세요.(그룹적용시 뜨네요.)

select bo_table, wr_parent from g4_board_new a where mb_id = 'aaaa' -- and a.wr_id = a.wr_parent and bo_table in Resource id #37 group by bo_table, wr_parent order by bn_id desc limit 10

1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #37 group by bo_table, wr_parent ' at line 4

error file : /g4board/board/index.php
윽.. 죄송합니다.

$tmp_bo_table_array = sql_query($sql_group);



$tmp_bo_table_array = sql_fetch_array($sql_group);

로 해주세요.
헙헙... 다시...

if ($member[mb_id])
{
$new_count = 10;
$tmp_gr_id = "불러올 그룹명";
$cnt = 0;

$sql_group = " select bo_table from $g4[board_table] where gr_id = '$tmp_gr_id' ";
$tmp_bo_table_array = sql_query($sql_group);

$sql = " select bo_table, wr_parent from $g4[board_new_table] a
where mb_id = '$member[mb_id]'
-- and a.wr_id = a.wr_parent
and bo_table in " . $tmp_bo_table_array . "
group by bo_table, wr_parent
order by bn_id desc
limit $new_count ";
$res = sql_query($sql);

echo "<table width=500 cellpadding=0 cellspacing=0>";

for ($i=0; $row=sql_fetch_array($res), $i<$new_count; $i++)
{
if (!$row[bo_table])
{
continue;
}

$tmp_table = $g4[write_prefix].$row[bo_table];
$sql2 = " select wr_subject, wr_comment from $tmp_table where wr_id = '$row[wr_parent]' ";
$row2 = sql_fetch($sql2);
$subj = get_text($row2[wr_subject]);
$comment = "";
if ($row2[wr_comment])
$comment = "<span class=small>($row2[wr_comment])</span>";
echo "<tr><td class=bg_menu2 title='$subj'>";
echo "<nobr style='display:block;overflow:hidden;width:400px;'>";
echo "<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row[wr_parent]'>";
echo "<span style='color:#438A01;'>$comment $subj</span></a>";
echo "</nobr></td></tr>";

을 아래와 같이 바꿔보세요.

if ($member[mb_id])
{
$new_count = 10;
$tmp_gr_id = "불러올 그룹명";
$cnt = 0;

$sql_group = " select bo_table from $g4[board_table] where gr_id = '$tmp_gr_id' ";
$tmp_bo_table_array = sql_query($sql_group);
for ($k=0; $tmp_row=sql_fetch_array($tmp_bo_table_array); $k++)
{
$bo_table_array[$k] = $tmp_row[bo_table];
}

$sql = " select bo_table, wr_parent from $g4[board_new_table] a
where mb_id = '$member[mb_id]'
-- and a.wr_id = a.wr_parent
and bo_table in " . $bo_table_array . "
group by bo_table, wr_parent
order by bn_id desc
limit $new_count ";
$res = sql_query($sql);

echo "<table width=500 cellpadding=0 cellspacing=0>";

for ($i=0; $row=sql_fetch_array($res), $i<$new_count; $i++)
{
if (!$row[bo_table])
{
continue;
}

$tmp_table = $g4[write_prefix].$row[bo_table];
$sql2 = " select wr_subject, wr_comment from $tmp_table where wr_id = '$row[wr_parent]' ";
$row2 = sql_fetch($sql2);
$subj = get_text($row2[wr_subject]);
$comment = "";
if ($row2[wr_comment])
$comment = "<span class=small>($row2[wr_comment])</span>";
echo "<tr><td class=bg_menu2 title='$subj'>";
echo "<nobr style='display:block;overflow:hidden;width:400px;'>";
echo "<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row[wr_parent]'>";
echo "<span style='color:#438A01;'>$comment $subj</span></a>";
echo "</nobr></td></tr>";
마지막, 장담합니다.


if ($member[mb_id])
{
$new_count = 10;
$tmp_gr_id = "불러올 그룹명";
$cnt = 0;

$sql_group = " select bo_table from $g4[board_table] where gr_id = '$tmp_gr_id' ";
$tmp_bo_table_array = sql_query($sql_group);
for ($k=0; $tmp_row=sql_fetch_array($tmp_bo_table_array); $k++)
{
$bo_table_array[$k] = "'{$tmp_row[bo_table]}'";
}

$split_list = implode(", ", $bo_table_array);
$bo_table_array = "({$split_list})";


$sql = " select bo_table, wr_parent from $g4[board_new_table] a
where mb_id = '$member[mb_id]'
-- and a.wr_id = a.wr_parent
and bo_table in " . $bo_table_array . "
group by bo_table, wr_parent
order by bn_id desc
limit $new_count ";
$res = sql_query($sql);

echo "<table width=500 cellpadding=0 cellspacing=0>";

for ($i=0; $row=sql_fetch_array($res), $i<$new_count; $i++)
{
if (!$row[bo_table])
{
continue;
}

$tmp_table = $g4[write_prefix].$row[bo_table];
$sql2 = " select wr_subject, wr_comment from $tmp_table where wr_id = '$row[wr_parent]' ";
$row2 = sql_fetch($sql2);
$subj = get_text($row2[wr_subject]);
$comment = "";
if ($row2[wr_comment])
$comment = "<span class=small>($row2[wr_comment])</span>";
echo "<tr><td class=bg_menu2 title='$subj'>";
echo "<nobr style='display:block;overflow:hidden;width:400px;'>";
echo "<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row[wr_parent]'>";
echo "<span style='color:#438A01;'>$comment $subj</span></a>";
echo "</nobr></td></tr>";

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기
🐛 버그신고