묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
질문)에러문의 - php게시판 페이지 나누는것
2004.07.07 15:00
http://www.ywa.go.kr/book/count.htmlphp 책을 보면서 db 관리하는 것 배우고 있는데요
배우면서 도서실 목록도 디비로 관리하면 웹상에서 모든 사람들이 보유 도서 검색도 할 수 있게요
그냥 간단하게 만들려고 하는데
밑에 페이지 나누는 부분에서 이상하게 출력이 되요
어디가 어떻게 잘못된것인지
책대로 했는데, 소스하나도 안 틀리게 하고요
제발 번호 제대로 나오게 해주세요. 그리고 번호링크도요
어디를 어떻게 고쳐야 하는지 부탁합니다.
소스는 다음과 같고요 어떻게 출력되는지 보시려면 링크 한번 봐주시고요.....
<?
include_once ("../book/dbcon.php");
include_once ("../book/function.php");
?>
<html>
<head>
<title>농업기술센터 도서목록 </title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr">
<link href="../book/ywa.css" rel="stylesheet" type="text/css">
<meta name="generator" content="Namo WebEditor v5.0">
</head>
<body>
<center><h3>전체 도서 목록</h3>
<?
///////////목록출력시작//////////////////////////
//변수초기화
$ipp=2;
$ten=5;
if ($page<=0) $page = 1;
if ($startpage<=0) $startpage = 1;
//현재페이지의 시작레코드를 찾습니다.
$startrow = ($page - 1) * $ipp;
//검색어 정의
if ($keyword!="") {
$sql_where = " where $keyfield like '%$keyword%' ";
}//if
//전체 글수 계산
$total_sql = "select count(no) from book_list";
$total_sql .= $sql_where;//검색조건
$res = mysql_query($total_sql);
if ($res) $rs = mysql_fetch_row($res);
$total_count = $rs[0];//검색된 글수
$totpage = ceil($total_count/$ipp);//총 페이지수 연산
//현재 페이지에 출력할 레코드 선택질의
$list_sql = "select * from book_list ";
$list_sql .= $sql_where;//검색조건
$list_sql .= " order by no desc";//정렬조건
$list_sql .= " limit $startrow, $ipp ";//한 페이지에 출력할 글수 제한
$res = mysql_query($list_sql);
?>
<hr>
<table width="800" height="24" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> Total <? echo number_format($totpage);?> pages / <? echo number_format($total_count);?>
권<img src="blank.gif" width="620" height="11" border="0"><a href="../book/index.html" target="_top">[홈]</a></td>
</tr>
</table>
<table width="800" align="center" cellspacing="0" bordercolordark="white" bordercolorlight="#999999" style="border-collapse:collapse;">
<tr><td height="18" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>번호</b></td><td height="18" width="172" align="center" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>도서분류</b></td><td height="18" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>도서<br>번호</b></td><td height="18" width="308" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>도서명</b></td><td height="18" width="79" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>제작사</b></td><td height="18" width="78" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>저자</b></td><td height="18" width="73" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>출판일</b></td></tr>
<?
if ($res) {
$i=0;
while ($rs = mysql_fetch_array($res)) {
$i++;
?>
<tr>
<td align=center height="25" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[no] ?></td>
<td align=center height="25" width="172" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;">
<p align="left"><?=$rs[branch] ?></td>
<td align=center height="25" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[bookno] ?></td>
<td align=center height="25" width="308" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[bookname] ?></td>
<td align=center height="25" width="79" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[publish] ?></td>
<td align=center height="25" width="78" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[author] ?></td>
<td align=center height="25" width="73" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[bookdate] ?></td>
</tr>
<?
}
}
?>
</table>
<table width="800" height="40" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#EBE8D8" style="border:0px #333333 solid;border-bottom-width:3px;">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="bottom">
<td style="color:#333333;font-size:12px;"><span style="font-weight:bold;">Go
to Page:</span>
<? if ($startpage>1) { ?>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='1'; search_form.page.value='1';search_form.submit();">◀</a>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='<? echo $startpage-$ten;?>'; search_form.page.value='<? echo $startpage-$ten;?>';search_form.submit();">이전</a>
<? }//if ?>
<?
$endpage = $startpage + $ten - 1;
if ($endpage>$totpage) $endpage = $totpage;
for ($i=$startpage;$i<=$endpage;$i++) {
if ($i==$page) {
echo "<b>[$i]</b>";
} else {
echo '<a href="javascript:search_form.page.value='$i';search_form.submit();">';
echo '[$i]';
echo '</a>';
}
}//for
?>
<? if ($endpage<$totpage) { ?>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='<? echo $startpage+$ten;?>'; search_form.page.value='<? echo $startpage+$ten;?>';search_form.submit();">다음</a>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='<? echo $totpage;?>'; search_form.page.value='<? echo $totpage;?>';search_form.submit();">▶</a>
<? }//if ?>
</td>
</tr>
</table>
</td>
<td>
<form action="<? echo $PHP_SELF;?>" method="get" name="search_form" id="search_form" style="margin:0px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> <input name="page" type="hidden" id="page" value="1">
<input name="startpage" type="hidden" id="startpage" value="1">
<select name="keyfield" id="keyfield">
<option value="branch" <? if($keyfield=="branch") echo "selected";?>>도서명</option>
<option value="publish" <? if($keyfield=="publish") echo "selected";?>>출판사</option>
<option value="author" <? if($keyfield=="author") echo "selected";?>>저자</option>
<option value="memo" <? if($keyfield=="memo") echo "selected";?>>기타 설명</option>
</select></td>
<td><input name="keyword" type="text" id="keyword" value="<? echo $keyword;?>" size="12">
</td>
<td>
<input type="submit" name="Submit" value="Search"></td>
</tr>
</table>
</form></td>
</tr>
</table>
<script>
function form2form(name,from,to) {
var fromObj, toObj;
fromObj = eval("document."+from+"."+name);
toObj = eval("document."+to + "."+name);
toObj.value = fromObj.value;
}
</script>
</body>
</html>
그럼 꼭 해결되기를 바라면서 부탁합니다.
제 이메일은 kingjsg@yw.go.kr
배우면서 도서실 목록도 디비로 관리하면 웹상에서 모든 사람들이 보유 도서 검색도 할 수 있게요
그냥 간단하게 만들려고 하는데
밑에 페이지 나누는 부분에서 이상하게 출력이 되요
어디가 어떻게 잘못된것인지
책대로 했는데, 소스하나도 안 틀리게 하고요
제발 번호 제대로 나오게 해주세요. 그리고 번호링크도요
어디를 어떻게 고쳐야 하는지 부탁합니다.
소스는 다음과 같고요 어떻게 출력되는지 보시려면 링크 한번 봐주시고요.....
<?
include_once ("../book/dbcon.php");
include_once ("../book/function.php");
?>
<html>
<head>
<title>농업기술센터 도서목록 </title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr">
<link href="../book/ywa.css" rel="stylesheet" type="text/css">
<meta name="generator" content="Namo WebEditor v5.0">
</head>
<body>
<center><h3>전체 도서 목록</h3>
<?
///////////목록출력시작//////////////////////////
//변수초기화
$ipp=2;
$ten=5;
if ($page<=0) $page = 1;
if ($startpage<=0) $startpage = 1;
//현재페이지의 시작레코드를 찾습니다.
$startrow = ($page - 1) * $ipp;
//검색어 정의
if ($keyword!="") {
$sql_where = " where $keyfield like '%$keyword%' ";
}//if
//전체 글수 계산
$total_sql = "select count(no) from book_list";
$total_sql .= $sql_where;//검색조건
$res = mysql_query($total_sql);
if ($res) $rs = mysql_fetch_row($res);
$total_count = $rs[0];//검색된 글수
$totpage = ceil($total_count/$ipp);//총 페이지수 연산
//현재 페이지에 출력할 레코드 선택질의
$list_sql = "select * from book_list ";
$list_sql .= $sql_where;//검색조건
$list_sql .= " order by no desc";//정렬조건
$list_sql .= " limit $startrow, $ipp ";//한 페이지에 출력할 글수 제한
$res = mysql_query($list_sql);
?>
<hr>
<table width="800" height="24" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> Total <? echo number_format($totpage);?> pages / <? echo number_format($total_count);?>
권<img src="blank.gif" width="620" height="11" border="0"><a href="../book/index.html" target="_top">[홈]</a></td>
</tr>
</table>
<table width="800" align="center" cellspacing="0" bordercolordark="white" bordercolorlight="#999999" style="border-collapse:collapse;">
<tr><td height="18" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>번호</b></td><td height="18" width="172" align="center" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>도서분류</b></td><td height="18" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>도서<br>번호</b></td><td height="18" width="308" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>도서명</b></td><td height="18" width="79" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>제작사</b></td><td height="18" width="78" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>저자</b></td><td height="18" width="73" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;" bgcolor="#BDBDBD">
<p align="center"><b>출판일</b></td></tr>
<?
if ($res) {
$i=0;
while ($rs = mysql_fetch_array($res)) {
$i++;
?>
<tr>
<td align=center height="25" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[no] ?></td>
<td align=center height="25" width="172" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;">
<p align="left"><?=$rs[branch] ?></td>
<td align=center height="25" width="34" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[bookno] ?></td>
<td align=center height="25" width="308" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[bookname] ?></td>
<td align=center height="25" width="79" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[publish] ?></td>
<td align=center height="25" width="78" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[author] ?></td>
<td align=center height="25" width="73" style="border-width:1; border-color:rgb(153,153,153); border-style:solid;"><?=$rs[bookdate] ?></td>
</tr>
<?
}
}
?>
</table>
<table width="800" height="40" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#EBE8D8" style="border:0px #333333 solid;border-bottom-width:3px;">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="bottom">
<td style="color:#333333;font-size:12px;"><span style="font-weight:bold;">Go
to Page:</span>
<? if ($startpage>1) { ?>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='1'; search_form.page.value='1';search_form.submit();">◀</a>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='<? echo $startpage-$ten;?>'; search_form.page.value='<? echo $startpage-$ten;?>';search_form.submit();">이전</a>
<? }//if ?>
<?
$endpage = $startpage + $ten - 1;
if ($endpage>$totpage) $endpage = $totpage;
for ($i=$startpage;$i<=$endpage;$i++) {
if ($i==$page) {
echo "<b>[$i]</b>";
} else {
echo '<a href="javascript:search_form.page.value='$i';search_form.submit();">';
echo '[$i]';
echo '</a>';
}
}//for
?>
<? if ($endpage<$totpage) { ?>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='<? echo $startpage+$ten;?>'; search_form.page.value='<? echo $startpage+$ten;?>';search_form.submit();">다음</a>
<a style="cursor:hand;color:#333333;font-weight:;font-size:12px;" onClick="search_form.startpage.value='<? echo $totpage;?>'; search_form.page.value='<? echo $totpage;?>';search_form.submit();">▶</a>
<? }//if ?>
</td>
</tr>
</table>
</td>
<td>
<form action="<? echo $PHP_SELF;?>" method="get" name="search_form" id="search_form" style="margin:0px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> <input name="page" type="hidden" id="page" value="1">
<input name="startpage" type="hidden" id="startpage" value="1">
<select name="keyfield" id="keyfield">
<option value="branch" <? if($keyfield=="branch") echo "selected";?>>도서명</option>
<option value="publish" <? if($keyfield=="publish") echo "selected";?>>출판사</option>
<option value="author" <? if($keyfield=="author") echo "selected";?>>저자</option>
<option value="memo" <? if($keyfield=="memo") echo "selected";?>>기타 설명</option>
</select></td>
<td><input name="keyword" type="text" id="keyword" value="<? echo $keyword;?>" size="12">
</td>
<td>
<input type="submit" name="Submit" value="Search"></td>
</tr>
</table>
</form></td>
</tr>
</table>
<script>
function form2form(name,from,to) {
var fromObj, toObj;
fromObj = eval("document."+from+"."+name);
toObj = eval("document."+to + "."+name);
toObj.value = fromObj.value;
}
</script>
</body>
</html>
그럼 꼭 해결되기를 바라면서 부탁합니다.
제 이메일은 kingjsg@yw.go.kr
싱글쿼터안에 변수명이나 특수문자는 무시됩니다.
예를들어..
<?
$i = 12;
echo "$i\n";
echo '$i\n';
?>
는
12 $i\n
로 출력된답니다..