쿼리문 차이가 뭘까 궁금하네요. 정보
쿼리문 차이가 뭘까 궁금하네요.본문
문득 list.php를 보다가 궁금해졌는데요..
게시물 갯수를 얻는 쿼립니다.
두 쿼리간에 차이가 있나요?
* 첫번째 쿼리
--------------------------------------------------------------
$sql = "select distinct wr_parent from $write_table";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);
--------------------------------------------------------------
*두번째 쿼리
--------------------------------------------------------------
$sql = "select * from $write_table where wr_is_comment = '0' ";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);
--------------------------------------------------------------
게시물 갯수를 얻는 쿼립니다.
두 쿼리간에 차이가 있나요?
* 첫번째 쿼리
--------------------------------------------------------------
$sql = "select distinct wr_parent from $write_table";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);
--------------------------------------------------------------
*두번째 쿼리
--------------------------------------------------------------
$sql = "select * from $write_table where wr_is_comment = '0' ";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);
--------------------------------------------------------------
댓글 전체
list.php의 코드 용도는 위와 다릅니다
무조건 wr_parent수를 뽑는 것이라니라 댓글에 검색어가 들어있을 경우
부모글 갯수를 추출하기 위해서 distinct를 사용하기 때문이죠
위 코드처럼 일반적인 카운트라면 아래처럼 하죠
$row = sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' ");
$total_count = $row[cnt];
무조건 wr_parent수를 뽑는 것이라니라 댓글에 검색어가 들어있을 경우
부모글 갯수를 추출하기 위해서 distinct를 사용하기 때문이죠
위 코드처럼 일반적인 카운트라면 아래처럼 하죠
$row = sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' ");
$total_count = $row[cnt];
그렇군요.. 사실 원본 list.php를 응용해서 다른걸 뭔가 하고 있었거든요.. 균이님 덕분에 배우고 갑니다. 가르쳐 주셔서 감사합니다.