묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
[re] 전체 소스를 올려봅니다. 뭐가 문제인지 ;;;
2003.04.10 07:21
페이지 넘기는 부분을 빼면 제대로 동작을 하는데,
페이지 넘기는 부분만 넣으면.. 리스트가 뜨다가..
페이지 넘어가려고 다음 페이지를 누르면 '검색된 자료수를 구하는 도중오류!'가 뜨더군요.
도대체 뭘 잘못 했는지 ㅡㅡ;;;
$keyset과 $searchword는 다른 페이지에서 넘어온 값을 사용합니다.
------------------------------------------
<?
$db_connect = mysql_connect("localhost","계정","패스워드");
mysql_select_db("디비명",$db_connect);
$page_no = 30;
$link_no = 10;
if($page <= 1) $page = 1;
$f_article = (int)(($page - 1) * $page_no);
$total = @mysql_fetch_array(mysql_query("select count(*) as t_cnt from 테이블명 where $keyset like '%$searchword%'",$db_connect)) or die("검색된 자료수를 구하는 도중오류!");
$half_page = (int)(($total[0] - 1) / $page_no) + 1;
$query_data = mysql_query("select * from 테이블명 where $keyset like '%$searchword%' order by artist asc limit $f_article,$page_no", $db_connect);
?>
<html>
<head>
<style type="text/css">
<!--
body { font-family: "Verdana"; font-size: 7pt}
A:link, A:active {font-size:7pt;color: black;text-decoration: none;}
A:visited {font-size: 7pt;color: black;text-decoration: none;}
A:hover {font-size: 7pt;color:F66901;text-decoration: underline;}
Td {font-family:Arial; font-size:7pt ;color: 000000; font-family:'Verdana';}
p {font-family:Arial; font-size:7pt ;color: 000000; font-family:'Verdana';}
body{ font-size: 7pt; font-family:'Verdana';}
-->
</style>
<title>검색 결과: Jazz (Bop, Bebop, Mainstream, Avant-garde, Cool)</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<p align="center"><b><font size="2">검색결과: Jazz (Bop, Bebop, Mainstream,
Avant-garde, Cool)</font></b></p>
<table width="900" border="0" cellspacing="0" cellpadding="4" align="center">
<tr bgcolor="#0033CC">
<td width="250">
<div align="center"><font color="#FFFFFF"><b>Artist</b></font></div>
</td>
<td width="245">
<div align="center"><font color="#FFFFFF"><b>Album</b></font></div>
</td>
<td width="30">
<div align="center"><font color="#FFFFFF"><b>Track</b></font></div>
</td>
<td width="275">
<div align="center"><font color="#FFFFFF"><b>Title</b></font></div>
</td>
<td width="40">
<div align="center"><font color="#FFFFFF"><b>Genre</b></font></div>
</td>
<td width="30">
<div align="center"><font color="#FFFFFF"><b>Year</b></font></div>
</td>
<td width="30">
<div align="center"><font color="#FFFFFF"><b>Bitrate</b></font></div>
</td>
</tr>
<?
while($rows=mysql_fetch_array($query_data))
{
$artist=$rows[artist];
$album=$rows[album];
$track=$rows[track];
$title=$rows[title];
$genre=$rows[genre];
$year=$rows[year];
$bitrate=$rows[bitrate];
echo ("
<tr bgcolor="#66CCFF" align="left">
<td width="250">
<font color="#FFFFFF"></font>$artist
</td>
<td width="245">
<font color="#FFFFFF"></font>$album
</td>
<td width="30">
<font color="#FFFFFF"></font>$track
</td>
<td width="275">
<font color="#FFFFFF"></font>$title
</td>
<td width="40">
<font color="#FFFFFF"></font>$genre
</td>
<td width="30">
<font color="#FFFFFF"></font>$year
</td>
<td width="30">
<font color="#FFFFFF"></font>$bitrate
</td>
</tr>
");
}
?>
</table>
<p>
<?
$f_link = (int)(($page - 1) / $link_no + 1) * $link_no - ($link_no - 1);
$l_link = $f_link + ($link_no - 1);
if($l_link > $half_page) $l_link = $half_page;
$prev = $f_link - 1;
$next = $l_link + 1;
$back = $page - 1;
$forward = $page + 1;
print "<center>";
if($link_no < $page) print "<b><a href=search.php?page=$prev>[10페이지 앞으로]</a></b> ";
if($back > "0") print "<b><a href=search.php?page=$back>[앞으로]</a></b>";
if($page != "1") :
print "<b><span style=font-size:8pt;><a href=search.php?page=1>[1]</a>...</span></b>";
endif;
for($i = $f_link; $i <= $l_link; $i++) :
if($page == $i) :
print "<span style=font-size:8pt;>[<u>$i</u>]</span>";
else :
print "<b><span style=font-size:8pt;><a href=search.php?page=$i>[$i]</a></span></b>";
endif;
endfor;
if($page != $half_page)
print "<b><span style=font-size:8pt;>...<a href=search.php?page=$half_page>[$half_page]</a></span></b>";
if($forward != ($half_page + 1))
print "<b><a href=search.php?page=$forward>[뒤로]</a></b>";
if($half_page > $next)
print " <b><a href=search.php?page=$next>[10페이지 뒤로]</a></b>";
mysql_close($db_connect);
?>
</body>
</html>
--------------------------------------------------
페이지 넘기는 부분만 넣으면.. 리스트가 뜨다가..
페이지 넘어가려고 다음 페이지를 누르면 '검색된 자료수를 구하는 도중오류!'가 뜨더군요.
도대체 뭘 잘못 했는지 ㅡㅡ;;;
$keyset과 $searchword는 다른 페이지에서 넘어온 값을 사용합니다.
------------------------------------------
<?
$db_connect = mysql_connect("localhost","계정","패스워드");
mysql_select_db("디비명",$db_connect);
$page_no = 30;
$link_no = 10;
if($page <= 1) $page = 1;
$f_article = (int)(($page - 1) * $page_no);
$total = @mysql_fetch_array(mysql_query("select count(*) as t_cnt from 테이블명 where $keyset like '%$searchword%'",$db_connect)) or die("검색된 자료수를 구하는 도중오류!");
$half_page = (int)(($total[0] - 1) / $page_no) + 1;
$query_data = mysql_query("select * from 테이블명 where $keyset like '%$searchword%' order by artist asc limit $f_article,$page_no", $db_connect);
?>
<html>
<head>
<style type="text/css">
<!--
body { font-family: "Verdana"; font-size: 7pt}
A:link, A:active {font-size:7pt;color: black;text-decoration: none;}
A:visited {font-size: 7pt;color: black;text-decoration: none;}
A:hover {font-size: 7pt;color:F66901;text-decoration: underline;}
Td {font-family:Arial; font-size:7pt ;color: 000000; font-family:'Verdana';}
p {font-family:Arial; font-size:7pt ;color: 000000; font-family:'Verdana';}
body{ font-size: 7pt; font-family:'Verdana';}
-->
</style>
<title>검색 결과: Jazz (Bop, Bebop, Mainstream, Avant-garde, Cool)</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<p align="center"><b><font size="2">검색결과: Jazz (Bop, Bebop, Mainstream,
Avant-garde, Cool)</font></b></p>
<table width="900" border="0" cellspacing="0" cellpadding="4" align="center">
<tr bgcolor="#0033CC">
<td width="250">
<div align="center"><font color="#FFFFFF"><b>Artist</b></font></div>
</td>
<td width="245">
<div align="center"><font color="#FFFFFF"><b>Album</b></font></div>
</td>
<td width="30">
<div align="center"><font color="#FFFFFF"><b>Track</b></font></div>
</td>
<td width="275">
<div align="center"><font color="#FFFFFF"><b>Title</b></font></div>
</td>
<td width="40">
<div align="center"><font color="#FFFFFF"><b>Genre</b></font></div>
</td>
<td width="30">
<div align="center"><font color="#FFFFFF"><b>Year</b></font></div>
</td>
<td width="30">
<div align="center"><font color="#FFFFFF"><b>Bitrate</b></font></div>
</td>
</tr>
<?
while($rows=mysql_fetch_array($query_data))
{
$artist=$rows[artist];
$album=$rows[album];
$track=$rows[track];
$title=$rows[title];
$genre=$rows[genre];
$year=$rows[year];
$bitrate=$rows[bitrate];
echo ("
<tr bgcolor="#66CCFF" align="left">
<td width="250">
<font color="#FFFFFF"></font>$artist
</td>
<td width="245">
<font color="#FFFFFF"></font>$album
</td>
<td width="30">
<font color="#FFFFFF"></font>$track
</td>
<td width="275">
<font color="#FFFFFF"></font>$title
</td>
<td width="40">
<font color="#FFFFFF"></font>$genre
</td>
<td width="30">
<font color="#FFFFFF"></font>$year
</td>
<td width="30">
<font color="#FFFFFF"></font>$bitrate
</td>
</tr>
");
}
?>
</table>
<p>
<?
$f_link = (int)(($page - 1) / $link_no + 1) * $link_no - ($link_no - 1);
$l_link = $f_link + ($link_no - 1);
if($l_link > $half_page) $l_link = $half_page;
$prev = $f_link - 1;
$next = $l_link + 1;
$back = $page - 1;
$forward = $page + 1;
print "<center>";
if($link_no < $page) print "<b><a href=search.php?page=$prev>[10페이지 앞으로]</a></b> ";
if($back > "0") print "<b><a href=search.php?page=$back>[앞으로]</a></b>";
if($page != "1") :
print "<b><span style=font-size:8pt;><a href=search.php?page=1>[1]</a>...</span></b>";
endif;
for($i = $f_link; $i <= $l_link; $i++) :
if($page == $i) :
print "<span style=font-size:8pt;>[<u>$i</u>]</span>";
else :
print "<b><span style=font-size:8pt;><a href=search.php?page=$i>[$i]</a></span></b>";
endif;
endfor;
if($page != $half_page)
print "<b><span style=font-size:8pt;>...<a href=search.php?page=$half_page>[$half_page]</a></span></b>";
if($forward != ($half_page + 1))
print "<b><a href=search.php?page=$forward>[뒤로]</a></b>";
if($half_page > $next)
print " <b><a href=search.php?page=$next>[10페이지 뒤로]</a></b>";
mysql_close($db_connect);
?>
</body>
</html>
--------------------------------------------------
댓글 3
-
특급잠수부
2003.04.10 09:00
-
한동은
2003.04.10 09:06
금방 눈에 안들어와서 한참 들여다 봐야겠네요 ^^;
구문구문 연구해 보고 또 질문드려도 될런지 ^^;;
매번 감사드립니다 특급잠수부님 ^^ -
한동은
2003.04.10 12:01
음..
나눠서 하는게 나중에 이용하기 편리하다는건 알겠는데,
원래 소스에 어떻게 응용을 해야할지 도통 감이 안오네여.. ㅡㅡ;;
눈깜짝할 사이에 세시간이 ;;;;;
ㅡㅜ
이런식보다는 따로따로 떼주셔서 하는게 좋습니다.
<?
if (empty($page)) $page = 1;
if (empty($list)) $list = 10;
if (empty($sort_col)) $sort_col = "artist";
if (empty($sort_key)) $sort_key = "";
$start_num = ($page - 1) * $list;
$wheresql = "";
if (isset($keyset) && $keyset != '')
{
if (isset($searchword) && $serachword != '')
{
if (preg_match("/where/",$wheresql)) $whereadd = "and";
else $whereadd = "where";
$wheresql .= $whereadd." $keyset like '%$searchword%'";
}
}
else $wheresql .= "";
$cnt_q = "select count(*) as t_cnt from TBL ".$wheresql;
$sel_q = "select * from TBL ".$wheresql." order by $sort_col $sort_key limit $start_num,$list";
$cnt_s = mysql_query($cnt_q,$conn) or die (mysql_error());
$cr = mysql_fetch_array($cnt_s);
$sel_s = mysql_query($sel_q,$conn) or die (mysql_error());
$total_page = ceil($cr[t_cnt] / $list);
if ($cr[t_cnt] == 0) echo ("<tr><td>등록된 정보없음.</td></tr>");
else
{
$count = $cr[t_cnt] - (($page - 1) * $list);
while ($sr = mysql_fetch_array($sel_s))
{
$count--;
}
}
?>