Search paging

Search paging

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

i have done a search script and now when i try something to search it give me the frist five rows(beacuse the limit is set to 5 rows per page) related to the search.When i click on the "next page" link it gives me the rows from the hole table instead to continue the rows from the search.

here is the code

<?php         $connection=mysql_connect('localhost', 'root', '***') or die(mysql_error());                 mysql_select_db("database");                           $posts_per_page = 5;        (!$_GET['start']) ? $start = 0 : $start = $_GET['start'];       $query = "SELECT COUNT(*) FROM posts  WHERE Description like '%".$_GET['Search']."%' or Topic like '%".$_GET['Search']."%'";       $result = mysql_query($query) or die (mysql_error());       $row = mysql_fetch_row($result);       $total_records = $row[0];       if (mysql_num_rows($result) > 0 )       {                      if (($total_records > 0) && ($start < $total_records))                      {         $query="SELECT * FROM Posts  WHERE Description like '%".$_GET['Search']."%' or Topic like '%".$_GET['Search']."%' ORDER BY ID desc LIMIT $start, $posts_per_page";       $result = mysql_query($query) or die (mysql_error());                      } include "PrintRows.php"; //next previous page links if ($start >= $posts_per_page) { echo "<a href=".$_SERVER['PHP_SELF']."?start=".($start-$posts_per_page)."> <= $start </a>"; } if ($start+$posts_per_page < $total_records && $start >= 0) {     $sum = $start + 5;   if ($start == 0){             echo "$start - <a href=".$_SERVER['PHP_SELF']."?start=".($start + $posts_per_page)."> $sum => </a>";            }   else   {    echo " -<a href=".$_SERVER['PHP_SELF']."?start=".($start + $posts_per_page)."> $sum => </a>";   } } } ?>

can anyone explain me this code
 (!$_GET['start']) ? $start = 0 : $start = $_GET['start'];



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

RutiX ::
can anyone explain me this code
 (!$_GET['start']) ? $start = 0 : $start = $_GET['start'];


Uzmi ovaj kod umjesto tog gore

$start = ( $_GET['start'] != '' ? (int) $_GET['start'] : 0);



offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

ok. can you explain the code?

Dopuna: 11 Maj 2007 2:09

i change the code, but still the same problem.

Dopuna: 11 Maj 2007 3:16

i found the problem but dont know how to fix it.

the problem is when i type a text in the search box it will remember it just for the first page but not for the next pages.

So how can i fix this, i should create a variable which will remember the value of the text box.Should i use arrays?

offline
  • Blood  Male
  • Ugledni građanin
  • Pridružio: 26 Jul 2003
  • Poruke: 384
  • Gde živiš: Beograd

Add to the links &search=$_GET['search']

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

i dont understand you. be more specific

offline
  • Blood  Male
  • Ugledni građanin
  • Pridružio: 26 Jul 2003
  • Poruke: 384
  • Gde živiš: Beograd

echo " -<a href=".$_SERVER['PHP_SELF']."?start=".($start + $posts_per_page)."&search=".$_GET['search']."> $sum => </a>";

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

thank you.Now it's working.

Ko je trenutno na forumu
 

Ukupno su 1363 korisnika na forumu :: 64 registrovanih, 9 sakrivenih i 1290 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 20624 - dana 04 Apr 2026 04:18

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: alonso, Apok, bankulen, bojcistv, cifra, Clouseau, comi991, Comyymoc, Denaya, Dimitrije Paunovic, DreadForce83, elenemste, Feller, Georgius, Giskard, Goxy1, Hemi, Jester, K a s p e r, krokodokodil, kybonacci, Lazur_01, Luka40, mane123, Marko Marković, Metanoja, Milometer, MiroslavD, Mis uz pusku, nelezele, nenomir, Nobunaga, Oklopnjak, Pekman, posmatrac300, Prašinar, precan, predragc, Prečanin30, Radoslava, raptorsi, samsung, sekretar, Simonsen23, sistem22, siwoti, Smiljkovich, stefan95, suponik, Tanjagre, Tas011, tesa, The Boss, trutcina, VJ, Vlad000, vlajkox, VNVK, Vodnik92, Wiesel092, zajcev1, ZetaMan, Zmaj Tolak, zziko