mysql 게시물 날짜순으로 랜덤으로 뽑기

mysql 게시물 날짜순으로 랜덤으로 뽑기

QA

mysql 게시물 날짜순으로 랜덤으로 뽑기

본문

안녕하세요?

리스트 정렬 필드에서 기본  wr_num,wr_reply를 사용하고 있습니다.

즉 wr_num 순서대로 파일을 뽑고 있는데요.

제가 궁금한 점은

현재

 

5file     날짜:1/7

4file     날짜:1/7

3file     날짜:1/7

2file     날짜:1/6

1file     날짜:1/6

0file     날짜:1/6

 

이런 상태로 출력 되고 있다면

 

3file   날짜:1/7

5file   날짜:1/7

4file   날짜:1/7

1file   날짜:1/6

0file   날짜:1/6

2file   날짜:1/6

 

이렇게  맨 처음 조건은 날짜순으로 그리고 다음 조건은 같은 날짜끼리에서 랜덤으로

출력 하고습니다.

 

이같은 쿼리문을 알려주시면 감사하겠습니다.

  

이 질문에 댓글 쓰기 :

답변 2

order by 날짜 desc, rand()

날짜부분만 컬럼명 넣어주세요. 날짜 정렬은 desc or asc 둘 중 하나 사용하시면 됩니다. 

테스트 한번 해보세요~  

답변 감사드립니다 씨에이치넷님
지금 상태가

admin/board_form.php 파일에서


  <select id="bo_sort_field" name="bo_sort_field">
                    <option value="" <?php echo get_selected($board['bo_sort_field'], ""); ?>>wr_num, wr_reply : 기본</option>
                    <option value="wr_datetime asc" <?php echo get_selected($board['bo_sort_field'], "wr_datetime asc"); ?>>wr_datetime asc : 날짜 이전것 부터</option>
                    <option value="wr_datetime desc" <?php echo get_selected($board['bo_sort_field'], "wr_datetime desc"); ?>>wr_datetime desc : 날짜 최근것 부터</option>
                    <option value="wr_hit asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_hit asc, wr_num, wr_reply"); ?>>wr_hit asc : 조회수 낮은것 부터</option>
                    <option value="wr_hit desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_hit desc, wr_num, wr_reply"); ?>>wr_hit desc : 조회수 높은것 부터</option>
                    <option value="wr_last asc" <?php echo get_selected($board['bo_sort_field'], "wr_last asc"); ?>>wr_last asc : 최근글 이전것 부터</option>
                    <option value="wr_last desc" <?php echo get_selected($board['bo_sort_field'], "wr_last desc"); ?>>wr_last desc : 최근글 최근것 부터</option>
                    <option value="wr_comment asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_comment asc, wr_num, wr_reply"); ?>>wr_comment asc : 댓글수 낮은것 부터</option>
                    <option value="wr_comment desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_comment desc, wr_num, wr_reply"); ?>>wr_comment desc : 댓글수 높은것 부터</option>
                    <option value="wr_good asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_good asc, wr_num, wr_reply"); ?>>wr_good asc : 추천수 낮은것 부터</option>
                    <option value="wr_good desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_good desc, wr_num, wr_reply"); ?>>wr_good desc : 추천수 높은것 부터</option>
                    <option value="wr_nogood asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_nogood asc, wr_num, wr_reply"); ?>>wr_nogood asc : 비추천수 낮은것 부터</option>
                    <option value="wr_nogood desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_nogood desc, wr_num, wr_reply"); ?>>wr_nogood desc : 비추천수 높은것 부터</option>
                    <option value="wr_subject asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_subject asc, wr_num, wr_reply"); ?>>wr_subject asc : 제목 오름차순</option>
                    <option value="wr_subject desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_subject desc, wr_num, wr_reply"); ?>>wr_subject desc : 제목 내림차순</option>
                    <option value="wr_name asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_name asc, wr_num, wr_reply"); ?>>wr_name asc : 글쓴이 오름차순</option>
                    <option value="wr_name desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "wr_name desc, wr_num, wr_reply"); ?>>wr_name desc : 글쓴이 내림차순</option>
                    <option value="ca_name asc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "ca_name asc, wr_num, wr_reply"); ?>>ca_name asc : 분류명 오름차순</option>
                    <option value="ca_name desc, wr_num, wr_reply" <?php echo get_selected($board['bo_sort_field'], "ca_name desc, wr_num, wr_reply"); ?>>ca_name desc : 분류명 내림차순</option>




 <option value="wr_datetime desc, rand()" <?php echo get_selected($board['bo_sort_field'], "wr_datetime desc, rand()"); ?>>rand() :최근것 부터 랜덤으로 표시</option>
             



 </select>


마지막부분에 이부분을 추가 시키고 관리자 화면에 들어가서 리스트정렬필드로 바꿔보려했는데 그대로인것같아요.

그런데  다른 간단한 테스트 결과 order by 날짜 desc, rand()  이게 맞다는건 알겠는데
적용이 안되네요. 혹시 다른 문제점이 있나요?

답변을 작성하시기 전에 로그인 해주세요.
전체 8
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT