소스좀 봐주세요..
본문
다른분이 만드신 랜덤출력 소스입니다. 출력방식이 wr_id값을 받아서 랜덤으로 출력하는 방식인데, 삭제된 게시물까지 불러오네요..
여기서 삭제된 게시물(wr_id) 안불러오고 싶은데, 어딜 수정해줘야 될까요?
<?php
$random_a = $_GET['bo_table'];
$wr_max_query = mysql_query('SELECT MAX(wr_id) AS wr_max FROM g5_write_'.$random_a; //가장높은번호글체크
$wr_max_q = mysql_fetch_array($wr_max_query);
$wr_max = $wr_max_q[wr_max];
$wr_rand = rand(1,$wr_max);
$wr_con_query = mysql_query('SELECT wr_is_comment wr_name wr_content FROM g5_write_'.$random_a.' where wr_id = '.$wr_rand);
$wr_con = mysql_fetch_array($wr_con_query);
if ($wr_con[wr_is_comment] == 1) {
$wr_con_t = 'comment';
?>
랜덤출력소스입니다..
!-->
답변 3
<?php
$sql_board = "select * from g5_board";
$res_board = mysql_query($sql_board);
$total_recordes = mysql_num_rows($res_board);
for ($j=0; $row_board=sql_fetch_array($res_board); $j++) {
if ($total_recordes-1 == $j) {
$sql_data .= "select * from g5_write_".$row_board[bo_table]." where wr_is_comment=0 ";
} else if ($j == 0){
$sql_data = "select * from g5_write_".$row_board[bo_table]." where wr_is_comment=0 union all " ;
} else {
$sql_data .= "select * from g5_write_".$row_board[bo_table]." where wr_is_comment=0 union all " ;
}
}
$sql_data .= " order by rand() limit 10";
$res_data = mysql_query($sql_data);
for ($i=0; $row=sql_fetch_array($res_data); $i++) {
echo $row[wr_subject]."<br>";
}?>
나머지는 알아서 수정하시길 바라요 ㅋ
limit 바꿔주시면 갯수 바뀝니다
질문있음 댓글 남겨주세요
!-->
삭제되면 db에서 삭제되지 않나요?
만약 db에서 삭제되지 않고 뭔가가 남아있다면 그걸 걸러내면 되긴 합니다..
$wr_con_query = mysql_query('SELECT wr_is_comment wr_name wr_content FROM g5_write_'.$random_a.' where wr_id = '.$wr_rand.' and wr_name != '' and wr_content != '' ");
이런형태로..
!-->
근데 이거 왜 이런방식으로 하는건가요? 쿼리자체에서 order by rand() 로 랜덤출력하면 되는데...
답변을 작성하시기 전에 로그인 해주세요.