aggiungere la paginazione

Stesso errore

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '&& modello.id = '9'' at line 1

PHP:
<?php
class MySQL{       
    function MySQL()       
    {       
        require_once "db_connect.php";  //metti l'once   
    }       
}
$aid = $_POST['aid'];   
    $bid = $_POST['bid']; 
     $cid = $_POST['cid'];       
$data = new MySQL();     
if(isset ($_POST['cerca_c'])){   
    $_SESSION['cerca_c']=$_POST['cerca_c'];   
}   
$cerca_c = mysql_escape_string(stripslashes($_SESSION['cerca_c'])); 
if (strlen($cerca_c) < 2 && $aid == "" && $bid == "" && $cid == "") { 
    echo "dati inseriti non validi"; 
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere   
}  else{  
  $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id)
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id)
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 "; 
if($cerca_c != "") { 
$q= " &&  (citta LIKE '%$cerca%')"; 
} 

if($aid != "") { 
$q= " && fascia.id = '$aid'"; 
} 
if($bid != "") { 
$q= " && tipo.id = '$bid'"; 
}
if($cid != "") { 
$q= " && modello.id = '$cid'"; 
}  
  
     $q = mysql_query($q) or die (mysql_error()) ;  
    $count=mysql_num_rows($q); 
    if($count == 0){  
        echo "Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave";  
        //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere es. registrati  
    }else{
 
Stesso errore

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '&& modello.id = '9'' at line 1

PHP:
<?php
class MySQL{       
    function MySQL()       
    {       
        require_once "db_connect.php";  //metti l'once   
    }       
}
$aid = $_POST['aid'];   
    $bid = $_POST['bid']; 
     $cid = $_POST['cid'];       
$data = new MySQL();     
if(isset ($_POST['cerca_c'])){   
    $_SESSION['cerca_c']=$_POST['cerca_c'];   
}   
$cerca_c = mysql_escape_string(stripslashes($_SESSION['cerca_c'])); 
if (strlen($cerca_c) < 2 && $aid == "" && $bid == "" && $cid == "") { 
    echo "dati inseriti non validi"; 
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere   
}  else{  
  $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id)
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id)
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 "; 
if($cerca_c != "") { 
$q= " &&  (citta LIKE '%$cerca_c%')"; 
} 

if($aid != "") { 
$q= " && fascia.id = '$aid'"; 
} 
if($bid != "") { 
$q= " && tipo.id = '$bid'"; 
}
if($cid != "") { 
$q= " && modello.id = '$cid'"; 
}  
  
     $q = mysql_query($q) or die (mysql_error()) ;  
    $count=mysql_num_rows($q); 
    if($count == 0){  
        echo "Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave";  
        //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere es. registrati  
    }else{
 
devi rimettere anche i punti

se non concateni la query ma lòa sovrascrivi

$q.=
 
finalmenteeeeeeee

FUNZIONAAAAAAAAAAAAAAAAAAAAAAA :)

grazie mille @borgo grazie milleeeee @criric

posto il codice se serve a qualcuno

PHP:
 <?php
class MySQL{       
    function MySQL()       
    {       
        require_once "db_connect.php";  //metti l'once   
    }       
}
$aid = $_POST['aid'];   
    $bid = $_POST['bid']; 
     $cid = $_POST['cid'];       
$data = new MySQL();     
if(isset ($_POST['cerca_c'])){   
    $_SESSION['cerca_c']=$_POST['cerca_c'];   
}   
$cerca_c = mysql_escape_string(stripslashes($_SESSION['cerca_c'])); 
if (strlen($cerca_c) < 2 && $aid == "" && $bid == "" && $cid == "") { 
    echo "dati inseriti non validi"; 
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere   
}  else{  
  $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id)
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id)
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 "; 
if($cerca_c != "") { 
$q.= " &&  (citta LIKE '%$cerca_c%')"; 
} 

if($aid != "") { 
$q.= " && fascia.id = '$aid'"; 
} 
if($bid != "") { 
$q.= " && tipo.id = '$bid'"; 
}
if($cid != "") { 
$q.= " && modello.id = '$cid'"; 
}  
  
     $q = mysql_query($q) or die (mysql_error()) ;  
    $count=mysql_num_rows($q); 
    if($count == 0){  
        echo "Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave";  
        //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere es. registrati  
    }else{  
        //visto che ci sono dati inseris

GRAZIEEEEEEEEEEEEEEEEEEEEEEEEEEE ;)
 
Buongiornoooo..

Piccolo problema con lo script ..... tutto ok mi trova i risultati ecc ecc .. ma c'è un problema .....

quando faccio la ricerca della città carica le pagine e se clicc o su 2 / 3 oppure avanti nella paginazione not problemmm

mentre invece se faccio una ricerca solo con usato oppure un'altro campo nella prima pagina trovo i risultati ma se mi forma la paginazione e quindi ho più pagine quando clicc o su 2/3 avanti ecc mi da' sempre i dati inseriti non sono validi

Secondo me il problema è qui:

PHP:
$cerca_m = mysql_escape_string(stripslashes($_SESSION['cerca_m'])); // questo non mi da' errore e vado avanti
if (strlen($cerca_m) < 2 && $aid == "" && $bid == "" && $cid == "") { // questo mi da errore e mi dice i dati inseriti non sono validi se vado avanti con le pagine
    echo "dati inseriti non validi";
Un po' di codice magari voi ci capite .... io l'ho solo implementato grazie voi
PHP:
  <?php
class MySQL{       
    function MySQL()       
    {       
        require_once "db_connect.php";  //metti l'once   
    }       
}
$aid = $_POST['aid'];   
    $bid = $_POST['bid']; 
     $cid = $_POST['cid'];
     $eid = $_POST['eid'];
     $fid = $_POST['fid'];
$data = new MySQL();     
if(isset ($_POST['cerca_m'])){   
    $_SESSION['cerca_m']=$_POST['cerca_m'];   
}   
$cerca_m = mysql_escape_string(stripslashes($_SESSION['cerca_m'])); 
if (strlen($cerca_m) < 2 && $aid == "" && $bid == "" && $cid == "" && $eid == "" && $fid == "") { 
    echo "dati inseriti non validi"; 
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere   
}  else{  
  $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN provincia ON (annunci.provinciaid=provincia.id)    
                           INNER JOIN regione ON (annunci.regioneid=regione.id)    
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id)
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id)
                           INNER JOIN cliente ON (annunci.clienteid=cliente.id)
                           INNER JOIN condizioni ON (annunci.condizioniid=condizioni.id)
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 "; 
if($cerca_m != "") { 
$q.= " &&  (citta LIKE '%$cerca_m%' OR regione LIKE '%$cerca_m%' OR provincia LIKE '%$cerca_m%'  )"; 
} 

if($aid != "") { 
$q.= " && fascia.id = '$aid'"; 
} 
if($bid != "") { 
$q.= " && tipo.id = '$bid'"; 
}
if($cid != "") { 
$q.= " && modello.id = '$cid'"; 
}  
if($eid != "") { 
$q.= " && cliente.id = '$eid'"; 
}
if($fid != "") { 
$q.= " && condizioni.id = '$fid'"; 
}
  
     $q = mysql_query($q) or die (mysql_error()) ;  
    $count=mysql_num_rows($q); 
    if($count == 0){  
        echo "Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave";  
        //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere es. registrati  
    }else{  
        //visto che ci sono dati inserisci anche la paginazione  
        require_once "paginazione.php";//metti l'once  
        $p = new Paging;  
        $max = 10;  
        // identifichiamo la pagina da cui iniziare la numerazione  
        $inizio = $p->paginaIniziale($max);  
        // troviamo il numero delle pagine che dovrà essere contato   
        $pagine = $p->contaPagine($count, $max);  
        $lim="LIMIT $inizio, $max";  
        $sq_lim=$q.$lim;//ripetere lo stesso codice uguale è sempre cattiva programmazione  
        $risultato=mysql_query($sq_lim);
 
Ultima modifica:
Perchè ricaricando la pagina perdi i dati in POST del form

Senza riscrivere tutto potresti provare ad usare le sessioni, tipo :

PHP:
session_start();
if (isset($_POST['aid'])) {
    $aid = $_POST['aid'];
    $_SESSION['aid'] = $aid;
} else {
    $aid = $_SESSION['aid'];
}

if(isset ($_POST['cerca_m'])){
$_SESSION['cerca_m']=$_POST['cerca_m'];
}
$cerca_m = mysql_escape_string(stripslashes($_SESSION['cerca_m']));
 
Ultima modifica:
Ciao e grazie per la risposta...

io in alto alla pagina ho già questo

PHP:
<?php if(!isset($_SESSION)){session_start ();} ?>

dici che non basta e devo aggiungere

PHP:
session_start();
if (isset($_POST['aid'])) {
    $aid = $_POST['aid'];
    $_SESSION['aid'] = $aid;
} else {
    $aid = $_SESSION['aid'];
}
 
certo
ogni campo che puo arrivarti dal form lo devi memorizzare in sessione

session_start(); lascialo giustamente a inizio pagina
 
Allora ...

ho fatto così

PHP:
<?php
 if(!isset($_SESSION)){session_start ();} 
  $aid = $_POST['aid']; 
 $bid = $_POST['bid']; 
$cid = $_POST['cid'];
  $eid = $_POST['eid']; 
   $fid = $_POST['fid']; 
  ?>

Ma non mi trasporta i dati :(


Ho fatto così e mi da errore

PHP:
<?php
 if(!isset($_SESSION)){session_start ():}
 
 
 $aid = $_POST['aid']; 
    $_SESSION['aid'] = $aid; 
} else { 
    $aid = $_SESSION['aid']; 
} 
$bid = $_POST['bid']; 
    $_SESSION['bid'] = $bid; 
} else { 
    $bid = $_SESSION['bid']; 
} 
$cid = $_POST['cid']; 
    $_SESSION['cid'] = $cid; 
} else { 
    $cid = $_SESSION['cid']; 
} 
$eid = $_POST['eid']; 
    $_SESSION['eid'] = $eid; 
} else { 
    $eid = $_SESSION['eid']; 
} 
$fid = $_POST['fid']; 
    $_SESSION['fid'] = $fid; 
} else { 
    $fid = $_SESSION['fid']; 
} 

 
  ?>
 
PHP:
<?php

session_start();

if (isset($_POST['aid'])) {
    $aid = $_POST['aid'];
    $_SESSION['aid'] = $aid;
} else {
    $aid = $_SESSION['aid'];
}
if (isset($_POST['bid'])) {
    $bid = $_POST['bid'];
    $_SESSION['bid'] = $bid;
} else {
    $bid = $_SESSION['bid'];
}
if (isset($_POST['cid'])) {
    $cid = $_POST['cid'];
    $_SESSION['cid'] = $cid;
} else {
    $cid = $_SESSION['cid'];
}
if (isset($_POST['eid'])) {
    $eid = $_POST['eid'];
    $_SESSION['eid'] = $eid;
} else {
    $eid = $_SESSION['eid'];
}
if (isset($_POST['fid'])) {
    $fid = $_POST['fid'];
    $_SESSION['fid'] = $fid;
} else {
    $fid = $_SESSION['fid'];
}
?>
 
metti semplicemente

session_start();

all'inizio

semmai posta il codice
 
Provato anche così ... :(


ti posto il codice della pagina

PHP:
<?php 

session_start(); 


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Usato barche nautica</title>
<meta name="description" content="Usato barche nautica: Il tuo sito di riferimento per trovare barche usate, accessori nautica, barche nuove, barche, accessori barche, barche a vela, maxy yacht, yacht. Insomma affidati a usato barche nautica per i tuoi acquisti di nuovo e usato barche. Ma non solo puoi trovare gommoni, moto d'acqua, open, vela, maxy vela, maxy yacht, yacht."/>
<meta name="keywords" content="usato barche, barche usate, barche a vela, barche a vela usate, maxy yacht, yacht, maxy vela, acquascooter, open, moto d'acqua."/>
<meta name="Classification" content="boats" />
<meta name="google-site-verification" content="6QSzgbo2IJFKxKpWdq5cZzXbux3fRisgPtzDqMDZUjA" />

<meta name="Classification" content="Usato barche nautica" />
<meta name="copyright" content="www.usatobarchenautica.it" />
<meta name="distribution" content="Global" />
<meta http-equiv="Content-Language" content="it-IT" />
<meta name="rating" content="Usato barche nautica, trova qualsiasi barca usata e nuova su usato barche nautica." />
<meta name="rating" content="General" />
<meta name="distribution" content="Global" />
<meta name="author" content="www.usatobarchenautica.it" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="revisit-after" content="1 days">
<link href="nautica.css" rel="stylesheet" type="text/css" />
<link href="modulo_ricerca.css" rel="stylesheet" type="text/css" />
<link href="login.css" rel="stylesheet" type="text/css" />
<link href="login_login.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-28058536-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>



<body>


<div class="container">
  <div class="header">
  <?php require "header.php" ; ?>
  <!-- end .header --></div>
   

  <div class="tab">
  <?php require "menutab.php" ; ?>
            
            
  </div>
 
 
 
 

<div class="ricerca">
      
      
     <?php require "menu_ricerca_home_chirurgico.php"; ?>

    <!-- end .ricerca --></div>
  <div class="sidebar1">
  <br />

   <a href="login_correct.php" /><button class="button orangeButt">Pubblica gratis</button></a>
<br />
<br />
  <div class="ex">
 
 <?php require "menu_laterale_motore.php" ?>
 
 
  </div>
<?php require "ci_trovi.php" ;?>
  </div>
  <div class="content">
  <?php require "autopromo.php" ; ?>
   <hr />
 


 <?php
class MySQL{       
    function MySQL()       
    {       
        require_once "db_connect.php";  //metti l'once   
    }       
}
$aid = $_POST['aid'];   
    $bid = $_POST['bid']; 
     $cid = $_POST['cid'];
     $eid = $_POST['eid'];
     $fid = $_POST['fid'];
$data = new MySQL();     
if(isset ($_POST['cerca_m'])){   
    $_SESSION['cerca_m']=$_POST['cerca_m'];   
}   
$cerca_m = mysql_escape_string(stripslashes($_SESSION['cerca_m'])); 
if (strlen($cerca_m) < 2 && $aid == "" && $bid == "" && $cid == "" && $eid == "" && $fid == "") { 
    echo "dati inseriti non validi"; 
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere   
}  else{  
  $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN provincia ON (annunci.provinciaid=provincia.id)    
                           INNER JOIN regione ON (annunci.regioneid=regione.id)    
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id)
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id)
                           INNER JOIN cliente ON (annunci.clienteid=cliente.id)
                           INNER JOIN condizioni ON (annunci.condizioniid=condizioni.id)
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 "; 
if($cerca_m != "") { 
$q.= " &&  (citta LIKE '%$cerca_m%' OR regione LIKE '%$cerca_m%' OR provincia LIKE '%$cerca_m%'  )"; 
} 

if($aid != "") { 
$q.= " && fascia.id = '$aid'"; 
} 
if($bid != "") { 
$q.= " && tipo.id = '$bid'"; 
}
if($cid != "") { 
$q.= " && modello.id = '$cid'"; 
}  
if($eid != "") { 
$q.= " && cliente.id = '$eid'"; 
}
if($fid != "") { 
$q.= " && condizioni.id = '$fid'"; 
}
  
     $q = mysql_query($q) or die (mysql_error()) ;  
    $count=mysql_num_rows($q); 
    if($count == 0){  
        echo "Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave";  
        //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere es. registrati  
    }else{  
        //visto che ci sono dati inserisci anche la paginazione  
        require_once "paginazione.php";//metti l'once  
        $p = new Paging;  
        $max = 10;  
        // identifichiamo la pagina da cui iniziare la numerazione  
        $inizio = $p->paginaIniziale($max);  
        // troviamo il numero delle pagine che dovrà essere contato   
        $pagine = $p->contaPagine($count, $max);  
        $lim="LIMIT $inizio, $max";  
        $sq_lim=$q.$lim;//ripetere lo stesso codice uguale è sempre cattiva programmazione  
        $risultato=mysql_query($sq_lim);  
       
        while($row=mysql_fetch_array($q)){     
            $click_annuncio = $row['click_annuncio'];  
$id_annunci = $row['id_annunci'];  
$user_id = $row['id'];
    $modello = $row['modello'];
  $messaggio = substr($row['messaggio'], 0, 25);  
  $mq = $row['mq'];
  $prezzo = $row['prezzo']; 
  $tipologia = $row['tipologia']; 
    $sigla = $row['sigla']; 
   $tipo = $row['tipo']; 
  $name = $row['name']; 
   $cliente = $row['cliente']; 
   $locali = $row['locali']; 
  $via = $row['via']; 
  $citta = $row['citta']; 
  $username = $row['username']; 
  $email = $row['email']; 
   $condizioni = $row['condizioni']; 
    $regione = $row['regione']; 
     $tipo = $row['tipo']; 
      $condizioni = $row['condizioni']; 
       $logo_cliente = $row['logo_cliente']; 
          
   
   $nome_file = $row['nome_file']; 
  $tipo_file = $row['tipo_file']; 
  $dati_file = $row['dati_file']; 
   
  $nome_file_vero = $row['nome_file_vero']; 
  $tipo_file = $row['tipo_file']; 
  $dati_file = $row['dati_file']; 
   
            //cosa ci sta a fare in mezzo a una table <p class='three'> eventualmente la class dalla al td o al tr 
            //tra l'altro non c'è la chiusura del tag </p> 
            //poi c'è una chiusura </table> nel mezzo (quindi hai messo due chiusure e una sila apertura) e 
            //ci sono dei tr non aperti ma solo chiusi 
            echo" <h5><table width='100%'>"; 
  echo" <tr>"; 
   echo" <p class='three'><td colspan='3'> <a href=\"rannunci.php?id=$id_annunci\"/>$via,$citta,$name,$sigla,$regione</a></td>"; 
 echo" </tr>"; 
 echo" <tr>"; 
  echo"  <td width='14%' bgcolor='#f4f9fd'> <a href=\"rannunci.php?id=$id_annunci\"/><img src='immagini2.php?id_annunci=$id_annunci' name='nome_file'  alt'' width='150' height='150'  /></a></td>"; 
  echo"  <td width='45%' bgcolor='#f4f9fd'><table width='100%'>"; 
   echo"   <tr>"; 
    echo"    <td>Stato Imbarcazione :<br /> $tipo <br /> Tipo imbarcazione: <br />$modello<br /></td>"; 
    echo"  </tr>"; 
    echo"  <tr>"; 
      echo"  <td> <a href=\"rannunci.php?id=$id_annunci\"/><button class=\"button orangeButt\">Vedi dettagli </button></td>"; 
echo"</tr>"; 
 echo"     <tr>"; 
    echo"    <td>&nbsp;</td>"; 
    echo"  </tr>"; 
   echo" </table></td>"; 
  echo"  <td width='31%' bgcolor='#f4f9fd'>Prezzo:$prezzo<br />Lunghezza:$mq<br />Cabine:$locali</p> <a href=\"rannunci.php?id=$id_annunci\"/><img src='immagini1.php?id=$user_id' name='nome_file_vero' width='150' height='40'/></a></td>"; 
  echo"</tr>"; 
echo"</table></h5>"; 

}  

        $lista = $p->listaPagine($_GET['p'], $pagine); 
        echo "<tr><td colspan=\"3\">"; 
        echo "$lista . <br>"; 
          $navigatore = $p->precedenteSuccessiva($_GET['p'], $pagine);  
         echo $navigatore;  
        echo "</td></tr>"; 
        echo"</table></h5>"; 
    }//fine if-else ci sono dati 
}//fine if-else post giusto 
?>


<hr />
  <!-- end .content --></div>
  <div class="sidebar2">
 
   <?php require "medium_home1.php" ; ?> <hr />
   <?php require "medium_home2.php" ; ?> 
   
  <!-- end .sidebar2 --></div>
  <div class="footer">

 <?php require "footer.php" ; ?>
    <!-- end .footer --></div>
  <!-- end .container --></div>
  <br />
  <br />
  

<map name="Map" id="Map">
  <area shape="rect" coords="127,214,184,237" href="usato_barche__nautica_sicilia.php" />
  <area shape="poly" coords="188,171,202,166,216,187,203,205,193,213" href="usato_barche__nautica_calabria.php" />
  <area shape="poly" coords="173,122,176,138,203,150,234,159,225,149,194,126" href="usato_barche__nautica_puglia.php" />
  <area shape="circle" coords="192,157,10" href="usato_barche__nautica_basilicata.php" />
  <area shape="poly" coords="179,158,169,140,153,138,157,151,176,164" href="usato_barche__nautica_campania.php" />
 
  
  <area shape="poly" coords="153,131,170,134,171,123,162,125" href="molise.php" />
  <area shape="rect" coords="114,92,129,108" href="usato_barche__nautica_umbria.php" />
<area shape="circle" coords="148,116,7" href="usato_barche__nautica_abruzzo.php" />
<area shape="poly" coords="139,138,103,115,114,109,132,117,140,125" href="usato_barche__nautica_lazio.php" />
<area shape="poly" coords="121,83,139,104,149,98,138,81,130,77" href="usato_barche__nautica_marche.php" />
<area shape="rect" coords="59,28,89,46" href="usato_barche__nautica_lombardia.php" />
<area shape="poly" coords="96,108,79,72,96,73,109,81,110,92,108,103" href="usato_barche__nautica_toscana.php" />
<area shape="poly" coords="113,77,71,61,71,50,100,54,115,58" href="usato_barche__nautica_emilia.php" />
<area shape="rect" coords="101,32,124,52" href="usato_barche__nautica_veneto.php" />
<area shape="poly" coords="37,74,20,45,45,35,52,48" href="usato_barche__nautica_piemonte.php" />

<area shape="poly" coords="98,31,90,22,95,11,115,8,111,21" href="usato_barche__nautica_trentino_alto_adige.php" />
<area shape="rect" coords="128,16,147,38" href="usato_barche__nautica_friuli_venezia_giulia.php" />
<area shape="rect" coords="32,133,71,193" href="usato_barche__nautica_sardegna.php" />
<area shape="circle" coords="26,33,6" href="usato_barche__nautica_valle_d_aosta.php" />
<area shape="poly" coords="72,71,61,59,43,69" href="usato_barche__nautica_liguria.php" />
</map>
</body>
</html>
 
I post li hai lasciati uguali pero

PHP:
$aid = $_POST['aid'];   
    $bid = $_POST['bid']; 
     $cid = $_POST['cid'];
     $eid = $_POST['eid'];
     $fid = $_POST['fid'];
$data = new MySQL();     
if(isset ($_POST['cerca_m'])){   
    $_SESSION['cerca_m']=$_POST['cerca_m'];   
}
 
Non vorrei crearti ancora piu confusione ma c'è una soluzione un po piu elegante

metti in sessione tutti i post con un ciclo

PHP:
<?php

class MySQL {

    function MySQL() {
        require_once "db_connect.php";  //metti l'once   
    }

}

$data = new MySQL();

// metti in sessione tutti i post con un ciclo
if (count($_POST) > 0) {
    foreach ($_POST as $key => $value) {
        $_SESSION[$key] = mysql_escape_string(stripslashes($value));
    }
}

if (strlen($_SESSION['cerca_m']) < 2 && $_SESSION['aid'] == "" && $_SESSION['bid'] == "" && $_SESSION['cid'] == "") {
    echo "dati inseriti non validi";
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere   
} else {
    $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id) 
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 ";
    if ($_SESSION['cerca_m'] != "") {
        $q = " &&  (citta LIKE '%" . $_SESSION['cerca_m'] . "%')";
    }

    if ($_SESSION['aid'] != "") {
        $q = " && fascia.fascia = '" . $_SESSION['aid'] . "'";
    }
    if ($_SESSION['bid'] != "") {
        $q = " && modello.modello = '" . $_SESSION['bid'] . "'";
    }
    if ($_SESSION['cid'] != "") {
        $q = " && tipo.tipo = '" . $_SESSION['cid'] . "'";
    }
    if ($_SESSION['eid'] != "") {
        $q.= " && cliente.id = '" . $_SESSION['eid'] . "'";
    }
    if ($_SESSION['fid'] != "") {
        $q.= " && condizioni.id = '" . $_SESSION['fid'] . "'";
    }


Se non ho fatto errori di sintassi dovrebbe andare anche cosi
 
Niente ...

ho sistemato anche qualche errore ma mi restituisce sempre questo:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '&& (citta LIKE '%torino%') && modello.id = '1'' at line 1


modifiche

PHP:
<?php 

class MySQL { 

    function MySQL() { 
        require_once "db_connect.php";  //metti l'once    
    } 

} 

$data = new MySQL(); 

// metti in sessione tutti i post con un ciclo 
if (count($_POST) > 0) { 
    foreach ($_POST as $key => $value) { 
        $_SESSION[$key] = mysql_escape_string(stripslashes($value)); 
    } 
} 

if (strlen($_SESSION['cerca_m']) < 2 && $_SESSION['aid'] == "" && $_SESSION['bid'] == "" && $_SESSION['cid'] == "" && $_SESSION['eid'] == "" && $_SESSION['fid'] == "") { 
    echo "dati inseriti non validi"; 
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere    
} else { 
   $q = "SELECT * FROM annunci  
                           INNER JOIN citta ON (annunci.cittaid=citta.id) 
                           INNER JOIN provincia ON (annunci.provinciaid=provincia.id)    
                           INNER JOIN regione ON (annunci.regioneid=regione.id)    
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id)
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id) 
                           INNER JOIN modello ON (annunci.modelloid=modello.id)
                           INNER JOIN cliente ON (annunci.clienteid=cliente.id)
                           INNER JOIN condizioni ON (annunci.condizioniid=condizioni.id)
                           INNER JOIN users ON (annunci.user_id=users.id) 
                           WHERE 1=1 "; 
                           
    if ($_SESSION['cerca_m'] != "") { 
        $q = " &&  (citta LIKE '%" . $_SESSION['cerca_m'] . "%')"; 
    } 
	
	

   if ($_SESSION['aid'] != "") { 
        $q.= " && fascia.id = '" . $_SESSION['aid'] . "'"; 
    }
   if ($_SESSION['bid'] != "") { 
        $q.= " && modello.id = '" . $_SESSION['bid'] . "'"; 
    }
     if ($_SESSION['cid'] != "") { 
        $q.= " && tipo.id = '" . $_SESSION['cid'] . "'"; 
    } 
	 if ($_SESSION['eid'] != "") { 
        $q.= " && cliente.id = '" . $_SESSION['eid'] . "'"; 
    }
    if ($_SESSION['fid'] != "") { 
        $q.= " && condizioni.id = '" . $_SESSION['fid'] . "'"; 
    }

  
     $q = mysql_query($q) or die (mysql_error()) ;  
    $count=mysql_num_rows($q); 
    if($count == 0){  
        echo "Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave";  
        //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere es. registrati  
    }else{  
        //visto che ci sono dati inserisci anche la paginazione  
        require_once "paginazione.php";//metti l'once  
        $p = new Paging;  
        $max = 10;  
        // identifichiamo la pagina da cui iniziare la numerazione  
        $inizio = $p->paginaIniziale($max);  
        // troviamo il numero delle pagine che dovrà essere contato   
        $pagine = $p->contaPagine($count, $max);  
        $lim="LIMIT $inizio, $max";  
        $sq_lim=$q.$lim;//ripetere lo stesso codice uguale è sempre cattiva programmazione  
        $risultato=mysql_query($sq_lim);
 
stampa e posta la query che generi

echo $q;


manca il punto

$q.=
 
Ultima modifica:
se aggiungo $q.=

mi da: Non ci sono risultati con la tua ricerca. Prova a cambiare la parola chiave
PHP:
<?php  

class MySQL {  

    function MySQL() {  
        require_once "db_connect.php";  //metti l'once     
    }  

}  

$data = new MySQL();  

// metti in sessione tutti i post con un ciclo  
if (count($_POST) > 0) {  
    foreach ($_POST as $key => $value) {  
        $_SESSION[$key] = mysql_escape_string(stripslashes($value));  
    }  
}  

if (strlen($_SESSION['cerca_m']) < 2 && $_SESSION['aid'] == "" && $_SESSION['bid'] == "" && $_SESSION['cid'] == "" && $_SESSION['eid'] == "" && $_SESSION['fid'] == "") {  
    echo "dati inseriti non validi";  
    //e qui il ritorno alla pagina di inserimento o a quella che ti fa più piacere     
} else {  
   $q = "SELECT * FROM annunci   
                           INNER JOIN citta ON (annunci.cittaid=citta.id)  
                           INNER JOIN provincia ON (annunci.provinciaid=provincia.id)     
                           INNER JOIN regione ON (annunci.regioneid=regione.id)     
                           INNER JOIN fascia ON (annunci.fasciaid=fascia.id) 
                            INNER JOIN tipo ON (annunci.tipoid=tipo.id)  
                           INNER JOIN modello ON (annunci.modelloid=modello.id) 
                           INNER JOIN cliente ON (annunci.clienteid=cliente.id) 
                           INNER JOIN condizioni ON (annunci.condizioniid=condizioni.id) 
                           INNER JOIN users ON (annunci.user_id=users.id)  
                           WHERE 1=1 ";  
                            
    if ($_SESSION['cerca_m'] != "") {  
        $q.= " &&  (citta LIKE '%" . $_SESSION['cerca_m'] . "%')";  
    }  
     
     

   if ($_SESSION['aid'] != "") {  
        $q.= " && fascia.id = '" . $_SESSION['aid'] . "'";  
    } 
   if ($_SESSION['bid'] != "") {  
        $q.= " && modello.id = '" . $_SESSION['bid'] . "'";  
    } 
     if ($_SESSION['cid'] != "") {  
        $q.= " && tipo.id = '" . $_SESSION['cid'] . "'";  
    }  
     if ($_SESSION['eid'] != "") {  
        $q.= " && cliente.id = '" . $_SESSION['eid'] . "'";  
    } 
    if ($_SESSION['fid'] != "") {  
        $q.= " && condizioni.id = '" . $_SESSION['fid'] . "'";  
    }
 
stampa la query è unico modo per vedere quali ci sono errori

PHP:
//alla fine della query
echo $q;

e copiala dal browser
 

Discussioni simili