Jump to content
  • 0

Страницы с поиском ...


JESS
 Share

Question

Я уже везде обсматрел как делать подстраничный вывод информации из БД,

есть много которые хорошо работают, если только ими листать информацию, а как дело подходит к поиску через форму так сразу начинают глючить.

Выводит найденную информацию, ссылки на страницы меняються в зависимости найденных файлов, но когда переходиш на вторую страницу чтобы посмотреть далле, то проишодит обновление страницы и все начнаеться по порядку с самой первой странице, помогите пожлуйста !!!

<form name="search_form" method="GET" action=<?php echo $_SERVER['PHP_SELF']; ?>>
<table cellpadding="2" cellspacing="4" bordercolordark="black" bordercolorlight="black">
<tr>
<td width="965" valign="top" align="center"><input type="text" name="search"></td>
</tr>
<tr>
<td width="965" valign="top" align="center"><input type="submit" value="OK" name=go></td>
</tr>
</table>
</form>


<?php

include "conn.php";

$lines_per_page = 3; //kol-vo strok na str
$sname='';
//$search='';

if(!empty($_GET['go']))
{
$sname = $_GET['search'];
}
//vsego zapiseyi
$query = "SELECT * FROM $tablename WHERE name LIKE '%$sname%' ";
$result = mysql_query($query);
$all_lines = mysql_num_rows($result);
//proveryaem ustanovlen li nomer str
if (!isset($page) or empty($page) or $page<=0) $page=1;
else $page=(int)$page;
$page_for_query = $page-1;
//s kakoy pozicii schitivat' zapisi
$lpos = $page_for_query * $lines_per_page;
//zapros




$query = "SELECT * FROM $tablename WHERE name LIKE '%$sname%' ORDER BY name ASC LIMIT $lpos,$lines_per_page";
$result = @mysql_query($query) or die("$query <b>failed!</b>
".mysql_error());


$count_pages = ceil($all_lines / $lines_per_page);
echo "<table><tr><td colspan=8 align=left>";
if ($count_pages>1) {
for ($i=1; $i<=$count_pages; $i++) {
if($page==$i and $i!=1) {echo " | <b><font style=color:#000000;<>$i</font>";}
elseif ($page==$i and $i==1) {echo "1";}
elseif($i==1 and $page!=$i) {echo " <a href="$PHP_SELF?page=$i" >$i</a>";}

elseif($i!=1 and $page!=$i) {echo " | <a href="$PHP_SELF?page=$i" >$i</a></b>";}
}
}
echo "</td></tr></table>";
WHILE ($row = MYSQL_FETCH_ROW($result))
$number = mysql_numrows($result);
if (!$number);
/* Print the relevant information */
$i = 0;


PRINT "<hr>";
WHILE ($i < $number):
$j = $i + 1 + ($page -1)*$lines_per_page;
$name = mysql_result($result,$i,"name");
$url = mysql_result($result,$i,"url");
$size = mysql_result($result,$i,"size");
$date = mysql_result($result,$i,"date");
$cat = mysql_result($result,$i,"cat1");
$dl = mysql_result($result, $i,"dl");
$id = mysql_result($result,$i,"id");
if ($i%2 == 0) {


PRINT "<tr bgcolor=#E8E8E8>
<!-- <td>$j</td>-->
<td><a href=$url>$name</a></td>

<td>$size</td>
<td>$dl</td>
</tr>

";
} else {
PRINT "<tr bgcolor=#cccccc>
<!--<td>$j</td> -->
<td><a href=$url>$name</a></td>

<td>$size</td>
<td>$dl</td>

</tr>
";

}

$i++;


ENDWHILE;

PRINT "</table></td></tr>";

/* Close the database connection */
MYSQL_CLOSE();

?>

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy