Problema urmatoarele rezultate in script cautare
Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
-
evident
- Mesaje:168
Problema urmatoarele rezultate in script cautare
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.) $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 " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>  ";
}
// 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 " <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?
MarPlo
Mesaje:4343
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:
Aceasta linie de cod:
evident
Mesaje:168
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
MarPlo
Mesaje:4343
Incearca asa:
Lasa in form cum ai pus
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";
evident
Mesaje:168
Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/a5045199/public_html/rezultat_cautare.php on line 79
linia 79
este }
MarPlo
Mesaje:4343
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"; }
evident
Mesaje:168
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";
Subiecte similare
- O mica problema de animatie CSS
HTML - XHTML - CSS
Primul mesaj
Noroc, MarPlo!
1. Am vizitat pe twitter un site de animatie, in care website-ul actual se numeste CSS-Challenges,com. In respectivul website, sunt...
Ultimul mesaj
1. Multumesc pentru raspuns.
2. Am inteles raspunsul tau: este un mic examen oferit voluntarilor online, pentru a le afla capacitatile de rezolvare...
- Problema curs de Engleza
Sesizari Erori si Greseli
Primul mesaj
Buna.
Am descarcat cursul curs_eurocor-engleza_incepatori_1-16.rar si cand vreau sa-l dezarhivez imi da eroarea asta:
An error occures whilw...
Ultimul mesaj
Buna,
Poti sa descarci cursul de engleza, nivel intermediar, de la urmatoarele linkuri:
- Lectiile 1-16...