Here is the script, help please do not want to browse with such a search, if you just print the table, everything is fine, and when the search is specified by name it does not want ..

<?php // Параметры подключения к базе данных define('DB_SE','server67.0hosting.me'); define('DB_LO','u8462856_test'); define('DB_PA','koloiko555'); define('DB_BA','u8462856_test'); class DB { public static function connect() { static $db = null; if ($db==null) $db = new DB(); return $db; } private $_handle = null; private function __construct() { $this->_handle = new mysqli(DB_SE, DB_LO, DB_PA, DB_BA); if ($this->_handle->connect_error) { die('Connect Error (' . $this->_handle->connect_errno . ') ' . $this->_handle->connect_error); } $this->_handle->query("SET NAMES utf8"); } public function __destruct() { $this->_handle->close(); } public function Test() { return $this->_handle; } public function Query($query) { $query = $this->_handle->query($query); return $query; } public function QueryNumRows($query) { return (($query===false) ? 0 : mysqli_num_rows($query)); } public function QueryArray($query) { if ($query===false) return false; unset($arr); $i = 0; if (mysqli_num_rows($query)>0) { while ($row = mysqli_fetch_array($query)) { foreach ($row as $key => $value) $arr[$i][$key] = $value; $i++; } } else { $arr = false; } unset($row); return $arr; } function ResultQueryArray($query) { return $this->QueryArray($this->Query($query)); } function ResultQueryNumRows($query) { return $this->QueryNumRows($this->Query($query)); } } function Query($query) { return DB::connect()->Query($query); } function QueryNumRows($query) { return DB::connect()->QueryNumRows($query); } function QueryArray($query) { return DB::connect()->QueryArray($query); } function ResultQueryArray($query) { return DB::connect()->ResultQueryArray($query); } function ResultQueryNumRows($query) { return DB::connect()->ResultQueryNumRows($query); } //название таблицы в базе $table="barigo"; // кол-во пользователей на странице $users_on_page="15"; $sql="select count(id) from `$table`"; $result = Query($sql); // считаем юзеров $count=mysqli_fetch_array($result); // считаем страницы $total=ceil($count[0]/$users_on_page); // страницы if(empty($_GET["p"])){$_GET["p"]="1";} $p=$_GET["p"]; $p=mysql_real_escape_string($p); if(!ctype_digit($p) or $p>$total): $p="1"; endif; // формируем запрос $first=$p*$users_on_page-$users_on_page; $zapros=("select * from `$table` WHERE `tovar` LIKE '%".strtoupper($_POST['nazv'])."%' limit $first, $users_on_page"); $result = ResultQueryArray($zapros); ?> <script type="text/javascript"> function surnam(){ var surname = document.getElementById('surname'); surname.style.border='1px solid #00ff00'; surname.value=''; } </script> <script type="text/javascript"> function poisk(){ var nazv = document.getElementById('nazv'); nazv.style.border='1px solid #00ff00'; nazv.value=''; } </script> <style> .bpdig { border: solid 1px #6f4a24 !important; background-color: #6e534c !important; width: 32px !important; height: 14px !important; color: #f6d9a6 !important; font-weight: bold !important; margin: 2px !important; text-align: center !important; } </style> <form action="poisk_name.php" method="post"> Поиск по названию (если хотите определенный товар): <input id="nazv" type="text" name="nazv" size="40" value="Сюда вводим слово или полностью название" onClick="poisk()"> <input type="submit" name="poissk" value="Поиск"> </form> <b>Начинаем с вобора события ... </b>: <select id="cd-dropdown" class="cd-select" onchange="top.location=this.value"> <option value="">Выбираем событие</option> <option value="?act=all" class="icon-1">Показать всё</option> <option value="?act=meloch" class="icon-1">Мелочуха</option> <option value="?act=cards" class="icon-2">Карты</option> <option value="?act=siyanie" class="icon-3">Сияние удачи</option> <option value="?act=zerkal" class="icon-4">Магия зеркал</option> <option value="?act=drag" class="icon-5">Драгоценные сундучки</option> <option value="?act=torgovoe" class="icon-6">Торговое путешествие</option> <option value="?act=meshochki" class="icon-7">Контробандные мешочки</option> </select> <form action="seach_gold.php" method="post"> Незнаете на чем заработать ?? Введите вашу скопленную сумму: <input id="surname" type="text" name="surname" size="1" value="Gold" onClick="surnam()"> <input type="submit" name="submit" value="Чем БаРыЖитЬ?"> </form> <table border="1"> <tbody> <tr> <td align="center"><b>#</b></td> <td align="center"><b>Наименование</b></td> <td align="center"><b>Куплен за</b></td> <td align="center"><b>Продан за</b> </td> <td align="center" width="120px"><b>Когда покупать?</b> </td> <td align="center" width="500px"><b>Подсчитано на калькуляторе</b></td> </tr> <?php $query = "SELECT id, tovar, kartinka, birjaz, birjas, birjam, aukz, auks, aukm, gosz, goss, gosm, kol, vremya, sobitie, kalkulator FROM `$table` WHERE `tovar` LIKE '%".strtoupper($_POST['nazv'])."%' limit $first, $users_on_page"; $result_array = ResultQueryArray($query); foreach($result_array as $row) { ?> <tr> <td> <?php print $row['id'] ?></td> <td align="center"> <?php print $row['tovar'] ?><br /> <table width="60" height="60" cellpadding="0" cellspacing="0" border="0" style="margin: 2px" background="http://w2.dwar.ru/images/data/artifacts/<?php print $row['kartinka'] ?>" title="<?php print $row['id'] ?>"> <tbody> <tr> <td valign="bottom"> <?php if ($row['kol']>'1') { print '<div class="bpdig">'.$row['kol'].'</div>'; } else { print ''; } ?> </td> </tr> </tbody> </table> </td> <td align="center"><?php print $row['birjaz'] ?> <?php print $row['birjas'] ?> <?php print $row['birjam'] ?></td> <td align="center"><?php print $row['aukz'] ?> <?php print $row['auks'] ?> <?php print $row['aukm'] ?></td> <td align="center"><?php print $row['sobitie'] ?></td> <br /> <td><?php print $row['kalkulator'] ?></td> </tr> <?php } ?> </tbody> </table> <?php if($total>1): #две назад print "<br><div>"; if(($p-2)>0): $ptwoleft="<a class='first_page_link' href='poisk_name.php?p=".($p-2)."'>".($p-2)."</a> "; else: $ptwoleft=null; endif; #одна назад if(($p-1)>0): $poneleft="<a class='first_page_link' href='poisk_name.php?p=".($p-1)."'>".($p-1)."</a> "; $ptemp=($p-1); else: $poneleft=null; $ptemp=null; endif; #две вперед if(($p+2)<=$total): $ptworight=" <a class='first_page_link' href='poisk_name.php?p=".($p+2)."'>".($p+2)."</a>"; else: $ptworight=null; endif; #одна вперед if(($p+1)<=$total): $poneright=" <a class='first_page_link' href='poisk_name.php?p=".($p+1)."'>".($p+1)."</a>"; $ptemp2=($p+1); else: $poneright=null; $ptemp2=null; endif; # в начало if($p!=1 && $ptemp!=1 && $ptemp!=2): $prevp="<a href='poisk_name.php' class='first_page_link' title='В начало'><<</a> "; else: $prevp=null; endif; #в конец (последняя) if($p!=$total && $ptemp2!=($total-1) && $ptemp2!=$total): $nextp=" ... <a href='poisk_name.php?p=".$total."'".$total."' class='first_page_link'>$total</a>"; else: $nextp=null; endif; print "<br>".$prevp.$ptwoleft.$poneleft.'<span class="num_page_not_link"><b>'.$p.'</b></span>'.$poneright.$ptworight.$nextp; print "</div>"; endif; mysql_close(); ?> </body></html> 

    1 answer 1

    This is not necessary:

     //название таблицы в базе $table="barigo"; // кол-во пользователей на странице $users_on_page="15"; $sql="select count(id) from `$table`"; $result = Query($sql); // считаем юзеров $count=mysqli_fetch_array($result); // считаем страницы $total=ceil($count[0]/$users_on_page); if(empty($_GET["p"])){$_GET["p"]="1";} $p=$_GET["p"]; $p=mysql_real_escape_string($p); if(!ctype_digit($p) or $p>$total): $p="1"; endif; // формируем запрос $first=$p*$users_on_page-$users_on_page; $zapros=("select * from `$table` WHERE `tovar` LIKE '%".strtoupper($_POST['nazv'])."%' limit $first, $users_on_page"); $result = ResultQueryArray($zapros); 

    better like this:

     //название таблицы в базе $table="barigo"; // кол-во пользователей на странице $users_on_page="15"; $sql="select count(id) as mycount from `$table`"; $result = ResultQueryArray($sql); // считаем юзеров $count=$result[0]['mycount']; // считаем страницы $total=ceil($count/$users_on_page); $p = (empty($_GET['p'])) ? ((intval($_GET['p'])>0) ? intval($_GET['p']) : 1 ) : 1; if ($p>$total) $p = 1; // формируем запрос $first=($p-1)*$users_on_page; $zapros=("select * from `$table` WHERE (tovar LIKE '%".strtoupper($_POST['nazv'])."%') limit $first, $users_on_page"); $result = ResultQueryArray($zapros); 

    And why not leafing through ... so maybe you have so many goods not to leaf through


    UPD As I said, you just do not have so many products to flip through them

    I corrected the code for you and removed your errors. Before you transfer to yourself - correct the links.

     <?php // Параметры подключения к базе данных define('DB_SE','server67.0hosting.me'); define('DB_LO','u8462856_test'); define('DB_PA','koloiko555'); define('DB_BA','u8462856_test'); class DB { public static function connect() { static $db = null; if ($db==null) $db = new DB(); return $db; } private $_handle = null; private function __construct() { $this->_handle = new mysqli(DB_SE, DB_LO, DB_PA, DB_BA); if ($this->_handle->connect_error) { die('Connect Error (' . $this->_handle->connect_errno . ') ' . $this->_handle->connect_error); } $this->_handle->query("SET NAMES utf8"); } public function __destruct() { $this->_handle->close(); } public function Test() { return $this->_handle; } public function Query($query) { $query = $this->_handle->query($query); return $query; } public function QueryNumRows($query) { return (($query===false) ? 0 : mysqli_num_rows($query)); } public function QueryArray($query) { if ($query===false) return false; unset($arr); $i = 0; if (mysqli_num_rows($query)>0) { while ($row = mysqli_fetch_array($query)) { foreach ($row as $key => $value) $arr[$i][$key] = $value; $i++; } } else { $arr = false; } unset($row); return $arr; } function ResultQueryArray($query) { return $this->QueryArray($this->Query($query)); } function ResultQueryNumRows($query) { return $this->QueryNumRows($this->Query($query)); } } function Query($query) { return DB::connect()->Query($query); } function QueryNumRows($query) { return DB::connect()->QueryNumRows($query); } function QueryArray($query) { return DB::connect()->QueryArray($query); } function ResultQueryArray($query) { return DB::connect()->ResultQueryArray($query); } function ResultQueryNumRows($query) { return DB::connect()->ResultQueryNumRows($query); } //название таблицы в базе $table="barigo"; // кол-во пользователей на странице $users_on_page="15"; $where = ""; if (!empty($_GET['nazv'])) { $_GET['nazv'] = strtoupper(addslashes(htmlspecialchars($_GET['nazv']))); $where = "WHERE (tovar LIKE '%".$_GET['nazv']."%') "; } else $_GET['nazv'] = ''; $sql="select count(id) as mycount from `$table` $where"; $result = ResultQueryArray($sql); // считаем юзеров $count=$result[0]['mycount']; // считаем страницы $total=ceil($count/$users_on_page); $p = (!empty($_GET['p'])) ? ((intval($_GET['p'])>0) ? intval($_GET['p']) : 1 ) : 1; if ($p>$total) $p = 1; // формируем запрос $first=($p-1)*$users_on_page; $zapros=("select * from `$table` $where limit $first, $users_on_page"); $result = ResultQueryArray($zapros); ?> <script type="text/javascript"> function surnam(){ var surname = document.getElementById('surname'); surname.style.border='1px solid #00ff00'; surname.value=''; } </script> <style> .bpdig { border: solid 1px #6f4a24 !important; background-color: #6e534c !important; width: 32px !important; height: 14px !important; color: #f6d9a6 !important; font-weight: bold !important; margin: 2px !important; text-align: center !important; } #nazv:focus { border: 1px solid #00ff00; } </style> <!--form action="poisk_name.php" method="get"--> <form action="" method="get"> Поиск по названию (если хотите определенный товар): <input id="nazv" type="text" name="nazv" size="40" value="<?php echo $_GET['nazv']; ?>" placeholder="Сюда вводим слово или полностью название"> <input type="submit" name="poissk" value="Поиск"> <a href="?p=1">Скинуть поиск</a> </form> <b>Начинаем с вобора события ... </b>: <select id="cd-dropdown" class="cd-select" onchange="top.location=this.value"> <option value="">Выбираем событие</option> <option value="?act=all" class="icon-1">Показать всё</option> <option value="?act=meloch" class="icon-1">Мелочуха</option> <option value="?act=cards" class="icon-2">Карты</option> <option value="?act=siyanie" class="icon-3">Сияние удачи</option> <option value="?act=zerkal" class="icon-4">Магия зеркал</option> <option value="?act=drag" class="icon-5">Драгоценные сундучки</option> <option value="?act=torgovoe" class="icon-6">Торговое путешествие</option> <option value="?act=meshochki" class="icon-7">Контробандные мешочки</option> </select> <form action="seach_gold.php" method="post"> Незнаете на чем заработать ?? Введите вашу скопленную сумму: <input id="surname" type="text" name="surname" size="1" value="Gold" onClick="surnam()"> <input type="submit" name="submit" value="Чем БаРыЖитЬ?"> </form> <table border="1"> <tbody> <tr> <td align="center"><b>#</b></td> <td align="center"><b>Наименование</b></td> <td align="center"><b>Куплен за</b></td> <td align="center"><b>Продан за</b> </td> <td align="center" width="120px"><b>Когда покупать?</b> </td> <td align="center" width="500px"><b>Подсчитано на калькуляторе</b></td> </tr> <?php // $query = "SELECT id, tovar, kartinka, birjaz, birjas, birjam, aukz, auks, aukm, gosz, goss, gosm, kol, vremya, sobitie, kalkulator FROM `$table` $where limit $first, $users_on_page"; // print $query.'<br>'; // $result_array = ResultQueryArray($query); // if ($result_array) // foreach($result_array as $row) if ($result) foreach($result as $row) { ?> <tr> <td> <?php print $row['id'] ?></td> <td align="center"> <?php print $row['tovar'] ?><br /> <table width="60" height="60" cellpadding="0" cellspacing="0" border="0" style="margin: 2px" background="http://w2.dwar.ru/images/data/artifacts/<?php print $row['kartinka'] ?>" title="<?php print $row['id'] ?>"> <tbody> <tr> <td valign="bottom"> <?php if ($row['kol']>'1') { print '<div class="bpdig">'.$row['kol'].'</div>'; } else { print ''; } ?> </td> </tr> </tbody> </table> </td> <td align="center"><?php print $row['birjaz'] ?> <?php print $row['birjas'] ?> <?php print $row['birjam'] ?></td> <td align="center"><?php print $row['aukz'] ?> <?php print $row['auks'] ?> <?php print $row['aukm'] ?></td> <td align="center"><?php print $row['sobitie'] ?></td> <br /> <td><?php print $row['kalkulator'] ?></td> </tr> <?php } ?> </tbody> </table> <?php if($total>1): #две назад print "<br><div>"; if(($p-2)>0): //$ptwoleft="<a class='first_page_link' href='poisk_name.php?nazv=".$_GET['nazv']."&p=".($p-2)."'>".($p-2)."</a> "; $ptwoleft="<a class='first_page_link' href='?nazv=".$_GET['nazv']."&p=".($p-2)."'>".($p-2)."</a> "; else: $ptwoleft=null; endif; #одна назад if(($p-1)>0): //$poneleft="<a class='first_page_link' href='poisk_name.php?nazv=".$_GET['nazv']."&p=".($p-1)."'>".($p-1)."</a> "; $poneleft="<a class='first_page_link' href='?nazv=".$_GET['nazv']."&p=".($p-1)."'>".($p-1)."</a> "; $ptemp=($p-1); else: $poneleft=null; $ptemp=null; endif; #две вперед if(($p+2)<=$total): //$ptworight=" <a class='first_page_link' href='poisk_name.php?nazv=".$_GET['nazv']."&p=".($p+2)."'>".($p+2)."</a>"; $ptworight=" <a class='first_page_link' href='?nazv=".$_GET['nazv']."&p=".($p+2)."'>".($p+2)."</a>"; else: $ptworight=null; endif; #одна вперед if(($p+1)<=$total): //$poneright=" <a class='first_page_link' href='poisk_name.php?nazv=".$_GET['nazv']."&p=".($p+1)."'>".($p+1)."</a>"; $poneright=" <a class='first_page_link' href='?nazv=".$_GET['nazv']."&p=".($p+1)."'>".($p+1)."</a>"; $ptemp2=($p+1); else: $poneright=null; $ptemp2=null; endif; # в начало if($p!=1 && $ptemp!=1 && $ptemp!=2): $prevp="<a href='?p=1' class='first_page_link' title='В начало'><<</a> "; else: $prevp=null; endif; #в конец (последняя) if($p!=$total && $ptemp2!=($total-1) && $ptemp2!=$total): //$nextp=" ... <a href='poisk_name.php?p=".$total."'".$total."' class='first_page_link'>$total</a>"; $nextp=" ... <a href='?p=".$total."'".$total."' class='first_page_link'>$total</a>"; else: $nextp=null; endif; print "<br>".$prevp.$ptwoleft.$poneleft.'<span class="num_page_not_link"><b>'.$p.'</b></span>'.$poneright.$ptworight.$nextp; print "</div>"; endif; ?> </body></html> 
    • Sorry, there are active pages that can be flipped) - Konstantin
    • 1 2 3 ... 5, and you press to the second page and the whole table comes out from the very beginning - Konstantin
    • what, even in my version on the second page is the whole page shown from the very beginning? - Stanislav
    • Yes, I changed, changed the value of $users_on_page="15"; on 3, what would 3 entries be displayed, in a search I enter a mask, the first 3 queries come out with a mask, I press the second page, the page is updated and displays the entire database without a search, and it does not even scroll - Constantine
    • and you are a cruel man, @ Konstantin =))) you probably lose sight of the fact that when you go through the pages you lose the search parameter that you first sent using the $ _POST method ... - Stanislav