Pagina 1 din 1

Problema urmatoarele rezultate in script cautare

Scris: Joi Mar 15, 2012
de evident
am gasit pe net urmatorul search form

Cod: Selectaţi tot

<html>
<head>
<title>designplace.org search script</title>
<meta name="author" content="">
</head>
<body>

<form name="form" action="search.php" method="get">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />
</form>
<?php
  // Get the search variable from URL
  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// rows to return
$limit=10; 

// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","username","password"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("database") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query = "select * from the_table where 1st_field like \"%$trimmed%\"  
  order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative
if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";

// google
 echo "<p><a href=\"http://www.google.com/search?q=" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";
  }

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["1st_field"];

  echo "$count.)&nbsp;$title" ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\"><< 
  Prev 10</a>&nbsp&nbsp;";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division
  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
 ?>
</body>
</html>
Problema e ca atunci cand dau sa imi afiseze urmatoarele rezultate nu merge.le arata tot pe primele
Stie cineva unde sa modific?

Problema urmatoarele rezultate in script cautare

Scris: Joi Mar 15, 2012
de MarPlo
Nu stiu sigur care-i problema, cel mai bine ar sti cel care l-a facut.
La o scurta privire, se pare ca nu preia din URL valoarea pt urmatoarele rezultate.
Incearca sa adaugi dupa:

Cod: Selectaţi tot

$var = @$_GET['q'] ;
Aceasta linie de cod:

Cod: Selectaţi tot

$s = isset($_GET['s']) ? $_GET['s'] : 0;

Problema urmatoarele rezultate in script cautare

Scris: Sâm Mar 17, 2012
de evident
Merge bine cum mi-ai zis tu dar si daca nu gaseste nici un rezultat tot imi da sa dau next si prev

Am in form asa:

Cod: Selectaţi tot

<form name="form" action="rezultat_cautare.php" method="get">
<fieldset>
<br/>
  Cauta:<input type="text" name="q" /> 
  Judetul: 
  <select name="judet">
  	  <option value="">Toate judetele</option>
      <option value="Alba">Alba</option>
      <option value="Arad">Arad</option>
      <option value="Arges">Arges</option>
      <option value="Bacau">Bacau</option>
      <option value="Bihor">Bihor</option>
      <option value="Bistrita-Nasaud">Bistrita-Nasaud</option>
      <option value="Botosani">Botosani</option>
      <option value="Braila">Braila</option>
      <option value="Brasov">Brasov</option>
      <option value="Buzau">Buzau</option>
      <option value="Calarasi">Calarasi</option>
      <option value="Caras-Severin">Caras-Severin</option>
      <option value="Cluj">Cluj</option>
      <option value="Constanta">Constansa</option>
      <option value="Covasna">Covasna</option>
      <option value="Dâmbovita">Dâmbovita</option>
      <option value="Dolj">Dolj</option>
      <option value="Galati">Galati</option>
      <option value="Giurgiu">Giurgiu</option>
      <option value="Gorj">Gorj</option>
      <option value="Harghita">Harghita</option>
      <option value="Hunedoara">Hunedoara</option>
      <option value="Ialomita">Ialomita</option>
      <option value="Iasi">Iasi</option>
      <option value="Ilfov">Ilfov</option>
      <option value="Maramures">Maramures</option>
      <option value="Mehedinti">Mehedinti</option>
      <option value="Mures">Mures</option>
      <option value="Neamt">Neamt</option>
      <option value="Olt">Olt</option>
      <option value="Prahova">Prahova</option>
      <option value="Salaj">Salaj</option>
      <option value="Satu Mare">Satu Mare</option>
      <option value="Sibiu">Sibiu</option>
      <option value="Suceava">Suceava</option>
      <option value="Teleorman">Teleorman</option>
      <option value="Timis">Timis</option>
      <option value="Tulcea">Tulcea</option>
      <option value="Vaslui">Vaslui</option>
      <option value="Vâlcea">Vâlcea</option>
      <option value="Vrancea">Vrancea</option>
    </select>
Categoria:  
<select name="categorie">
	  <option value="">Toate categoriile</option>
      <option value="Afaceri">Afaceri</option>
      <option value="Articole">Articole</option>
      <option value="Animale">Animale</option>
      <option value="Anticariat">Anticariat</option>
      <option value="Arta-Antichitati">Arta si Antichitati</option>
      <option value="Auto">Auto</option>
      <option value="Calculatoare">Calculatoare</option>
      <option value="Colectii">Colectii</option>
      <option value="Constructii">Constructii</option>
      <option value="Diverse">Diverse</option>
      <option value="Donatii">Donatii</option>
      <option value="Electrice">Electrice</option>
      <option value="Foto">Foto</option>
      <option value="Hobby">Hobby</option>
      <option value="Imobiliare">Imobiliare</option>
      <option value="Locuri-de-munca">Locuri de munca</option>
      <option value="Matrimoniale">Matrimoniale</option>
      <option value="Moda">Moda</option>
      <option value="Mobilier">Mobilier</option>
      <option value="Moto-Velo">Moto Velo</option>
      <option value="Media-Publicitate">Media Publicitate</option>
      <option value="Muzica">Muzica</option>
      <option value="Pierderi-Gasiri">Pierderi Gasiri</option>
      <option value="Servicii">Servicii</option>
      <option value="Sport">Sport</option>
      <option value="Turism">Turism</option>
      <option value="Telefoane">Telefoane</option>
    </select>
  <input type="submit" name="Submit" value="Search" />
  </fieldset>
</form>
si in php am :

Cod: Selectaţi tot

$query = "select * from anunturi where categorie='$categorie_search' and judet='$judet_search'and titluanunt like \"%$trimmed%\"  
  order by id";
cum pot sa fac in form o chestie care sa caute in toate judetele respectiv toate categoriile.
ca daca pun <option value="">Toate judetele</option> nu gaseste nimic...pentru ca trebuie sa fie gol in coloana din db

Problema urmatoarele rezultate in script cautare

Scris: Sâm Mar 17, 2012
de MarPlo
Incearca asa:
Lasa in form cum ai pus

Cod: Selectaţi tot

<option value="">Toate judetele</option>
Ia $query sa fie asa:

Cod: Selectaţi tot

$query = "select * from anunturi where categorie='$categorie_search' ".(strlen($judet_search)>1 ? "and judet='$judet_search'" : '')." and titluanunt like \"%$trimmed%\"  
  order by id";

Problema urmatoarele rezultate in script cautare

Scris: Dum Mar 18, 2012
de evident
Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/a5045199/public_html/rezultat_cautare.php on line 79

linia 79
este }

Problema urmatoarele rezultate in script cautare

Scris: Dum Mar 18, 2012
de MarPlo
Nu stiu care sa fie cauza.
Incearca sa rezolvi si tu, depanand scriptul, poate lipseste undeva un caracter de inchidere punct si virgula (;), sau vreo paranteza, ori caracter punct de unire siruri.

Daca nu te descurci cu sintaxa data mai sus, poti face asa (e acelasi lucru):

Cod: Selectaţi tot

if(strlen($judet_search) > 1) { $query = "select * from anunturi where categorie='$categorie_search' and judet='$judet_search' and titluanunt like \"%$trimmed%\" order by id"; }
else { $query = "select * from anunturi where categorie='$categorie_search' and titluanunt like \"%$trimmed%\" ORDER BY id"; }
 

Problema urmatoarele rezultate in script cautare

Scris: Lun Mar 19, 2012
de evident
eu tot am incercat sa ma uit si sa fac.am incercat cam tot.nu stiu ce poate sa aiba.
folosesc

Cod: Selectaţi tot

$query = "select * from anunturi where categorie='$categorie_search' ".(strlen($judet_search)>1 ? "and judet='$judet_search'" : '')." and titluanunt like \"%$trimmed%\"  
  order by id";