DB에서 wr_id 값을 불러와서 wr_num, wr_parent에 넣고싶습니다. 채택완료
DB에 현재 10개의 데이터가 있다고 가정할때,
wr_id 에 값이 1 ~ 10 의숫자가 아니라
1,2,3,5,9,11 ... 이렇게 불규칙적으로 저장이되어있습니다.
이렇게 불규칙적인 wr_id 를 한개씩 가져와서 wr_num과 wr_parent 에 각각 넣고싶은데
코드를 어떻게 짜야할지 감이안와서 도움을 요청합니다..ㅜㅜ
예)
DB
wr_id wr_num wr_parent 코드 실행후 wr_id wr_num wr_parent
1 0 0 1 -1 1
2 0 0 --> 2 -2 2
4 0 0 4 -4 4
.... ....
이렇게 하고싶습니다...
</span></p><p><span style="font-size: 14.6667px;"><?php</span></p><p><span style="font-size: 14.6667px;">include_once('./_common.php'); </span></p><p><span style="font-size: 14.6667px;"> </span></p><p><span style="font-size: 14.6667px;">$table = "g5_write_test01";</span></p><p><span style="font-size: 14.6667px;"> </span></p><p><span style="font-size: 14.6667px;">$count = "select count(*) from $table";</span></p><p><span style="font-size: 14.6667px;">$result = sql_query($count);</span></p><p><span style="font-size: 14.6667px;">$row = sql_fetch_array($result);</span></p><p><span style="font-size: 14.6667px;">$co = $row["count(*)"];</span></p><p><span style="font-size: 14.6667px;"> </span></p><p><span style="font-size: 14.6667px;">//wr_parent 값</span></p><p><span style="font-size: 14.6667px;">$wr_num = "select min(wr_id) as wr_id from $table ";</span></p><p><span style="font-size: 14.6667px;">for($i = 0; $i<=$co; $i++ ){</span></p><p><span style="font-size: 14.6667px;">//이곳에 update 문을 사용해서 한줄씩 추가하고싶습니다..</span></p><p> </p><p><span style="font-size: 14.6667px;">}</span></p><p><span style="font-size: 14.6667px;">?></span></p><p><span style="font-size: 14.6667px;">
이렇게 코드는 짜봣는데 도통 for문안에 어떤식으로 update를 해야할지 감이안옵니다..ㅜㅜ
답변 3개
</p><p>$sql = "update $table set wr_parent = wr_id, wr_num = (0-wr_id) ";</p><p>sql_query($sql);</p><p>
요렇게 하면 한방에 될 듯 한데요.
원글이나 답글 제외가 필요하면where절에 조건을 추가하면 되고요.
답변에 대한 댓글 4개
for문은 전체 테이블 count 한 수만큼 반복을 하는데 어떻게 해야하나요??
where wr_reply = "" // 답글제외
where wr_reply <> "" // 원글제외
머 요런식이죠.
댓글을 작성하려면 로그인이 필요합니다.
$sql = " select * from g5_write_test01";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$sql = "update g5_write_test01 set wr_parent = wr_id where wr_id = {$row['wr_id']} ";
sql_query($sql);
}
대략이런식..
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인