번호 매기기
본문
db 정보들을 들고와서 뿌려주는 페이지를 만들고 있습니다.
제가 원하는건 다 됐는데...
번호를 매기고 싶은데 어떻게 해야되나요?ㅠ
예를들어 총 개수가 5개면
최신거는
5
4
3
2
1
이런식으로 번호를 매기고 싶습니다....
$common_idx = "idx";
$sql_common = " from list";
$sql_search = " where (1) ";
$update_url = "./update.php";
if ($stx) {
$sql_search .= " and ( ";
switch ($sfl) {
case "bo_table" :
$sql_search .= " ($sfl like '$stx%') ";
break;
case "a.gr_id" :
$sql_search .= " ($sfl = '$stx') ";
break;
default :
$sql_search .= " ($sfl like '%$stx%') ";
break;
}
$sql_search .= " ) ";
}
if (!$sst) {
$sst = "idx";
$sod = "desc";
}
$sql_order = " order by $sst $sod ";
$sql = " select count(*) as cnt {$sql_common} {$sql_search} and del != 'y' {$sql_order} ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$rows = '20';
$total_page = ceil($total_count / $rows); // 전체 페이지 계산
if ($page < 1) { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함
$sql = " select * {$sql_common} {$sql_search} and del != 'y' {$sql_order} limit {$from_record}, {$rows} ";
$result = sql_query($sql);
?>
<div class="tbl_head01 ">
<table class="tbl_wrap">
<caption><?php echo $g5['title']; ?> 목록</caption>
생략
<tbody>
<?php
for ($i=0; $row=sql_fetch_array($result); $i++) {
?>
<tr class="<?php echo $bg; ?>">
<td>
????번호 어떻게???
</td>
<td>
<?php echo get_text($row['name']) ?>
</td>
</tr>
이하 생략
답변 1
$num = $total_count -($page-1)*$rows;
for ($i=0; $row=sql_fetch_array($result); $i++) {
echo $num;
$num--;
}
이런식으로 적용해보세요.
답변을 작성하시기 전에 로그인 해주세요.