테스트 사이트 - 개발 중인 베타 버전입니다

소스좀 봐주세요.. 채택완료

AmoA 10년 전 조회 4,860

다른분이 만드신 랜덤출력 소스입니다. 출력방식이 wr_id값을 받아서 랜덤으로 출력하는 방식인데, 삭제된 게시물까지 불러오네요..

여기서 삭제된 게시물(wr_id) 안불러오고 싶은데, 어딜 수정해줘야 될까요?

 

 

</p><p><?php</p><p>$<span style="font-size: 13.3333330154419px; line-height: 1.5;">random_a</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;"> = $_GET['bo_table'];</span></p><p> </p><p>$wr_max_query = mysql_query('SELECT MAX(wr_id) AS wr_max FROM g5_write_'.$<span style="font-size: 13.3333330154419px; line-height: 1.5;">random_a</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;">; //가장높은번호글체크</span></p><p>$wr_max_q = mysql_fetch_array($wr_max_query);</p><p>$wr_max = $wr_max_q[wr_max];</p><p>$wr_rand = rand(1,$wr_max); </p><p>$wr_con_query = mysql_query('SELECT wr_is_comment wr_name wr_content FROM g5_write_'.$random_a.' where wr_id = '.$wr_rand); </p><p>$wr_con = mysql_fetch_array($wr_con_query);</p><p>if ($wr_con[wr_is_comment] == 1) {</p><p><span class="Apple-tab-span" style="white-space: pre;">	</span>$wr_con_t = 'comment'; </p><p>?></p><p>

 

랜덤출력소스입니다..

 

 

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

답변 3개

채택된 답변
+20 포인트
10년 전

</p><p><?php</p><p>$sql_board = "select * from g5_board";</p><p>$res_board = mysql_query($sql_board);</p><p>$total_recordes = mysql_num_rows($res_board);</p><p>for ($j=0; $row_board=sql_fetch_array($res_board); $j++) {</p><p> </p><p>if ($total_recordes-1 == $j) {</p><p><span class="Apple-tab-span" style="white-space:pre">	</span>$sql_data .= "select * from g5_write_".$row_board[bo_table]." where wr_is_comment=0  ";</p><p>} else if ($j == 0){</p><p><span class="Apple-tab-span" style="white-space:pre">	</span>$sql_data = "select * from g5_write_".$row_board[bo_table]." where wr_is_comment=0 union all " ;</p><p>} else {</p><p><span class="Apple-tab-span" style="white-space:pre">	</span>$sql_data .= "select * from g5_write_".$row_board[bo_table]." where wr_is_comment=0 union all " ;</p><p>}</p><p>}</p><p> </p><p>$sql_data .= " order by rand() limit 10";</p><p>$res_data = mysql_query($sql_data);</p><p>for ($i=0; $row=sql_fetch_array($res_data); $i++) {</p><p>echo $row[wr_subject]."
";</p><p>}?> </p><p>

 

나머지는 알아서 수정하시길 바라요 ㅋ

limit 바꿔주시면 갯수 바뀝니다

질문있음 댓글 남겨주세요

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

A
AmoA
10년 전
감사합니다! 잘쓰겠습니다 :)

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

10년 전
근데 이거 왜 이런방식으로 하는건가요? 쿼리자체에서 order by rand() 로 랜덤출력하면 되는데...
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

A
AmoA
10년 전
초보라 인터넷에 올려진소스 주워 사용하다보니 랜덤소스중에 저게 유일하게 되서 사용하게 됐습니다..
phpmyadmin 쿼리에서 select * from g5_write_humor where wr_is_comment=0 order by rand() limit 1 이렇게 하면 한개씩 출력되긴하는데, 이걸 제가올린소스에 수정해 삽입하면 되나요??

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

10년 전

삭제되면 db에서 삭제되지 않나요?

만약 db에서 삭제되지 않고 뭔가가 남아있다면 그걸 걸러내면 되긴 합니다..

 

</p><p><code class="variable" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; color: rgb(170, 119, 0) !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">$wr_con_query</code><span style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13.0799999237061px; line-height: 23.5440006256104px; background-color: rgb(248, 248, 248);"> </span><code class="plain" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">= mysql_query(</code><code class="string" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; color: blue !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">'SELECT wr_is_comment wr_name wr_content FROM g5_write_'</code><code class="plain" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">.</code><code class="variable" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; color: rgb(170, 119, 0) !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">$random_a</code><code class="plain" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">.</code><code class="string" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; color: blue !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">' where wr_id = '</code><code class="plain" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">.</code><code class="variable" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; color: rgb(170, 119, 0) !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">$wr_rand.' and wr_name != '' and wr_content != '' "</code><code class="plain" style="line-height: 23.5440006256104px; font-size: 13.0799999237061px; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; background-image: none !important; background-attachment: initial !important; background-color: rgb(248, 248, 248); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">);</code><span style="font-size: 10pt; line-height: 1.5;">​</span></p><p><span style="font-size: 10pt; line-height: 1.5;"></span><span style="font-size: 13.3333330154419px; line-height: 1.5;">

 

이런형태로.. 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

A
AmoA
10년 전
소스적용하면 $wr_con부분부터 적용이 안되서(흰색으로나오네요) 레이아웃이깨지네요.. 아마도 랜덤소스가 게시물이 1000개라면 삭제여부에 상관없이 1~1000의 게시물번호중에서 한개 골라주는 형식인 듯 합니다..

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

답변을 작성하려면 로그인이 필요합니다.

로그인