Mistero Join

searedone

Utente Attivo
11 Giu 2010
508
0
0
Ciao a tutti ... chi riesce a farmi capire cosa sbaglio ???

Sto facendo un semplicissimo motore di ricerca interno, e tutto funziona, il db è un db relazionale, e fuzniona perfettamente, il problema è nel printare il risultato ...

cerca.php
PHP:
<form action='cerca.php?ricerca=ok' method='POST'> 


  <input type='text' tabindex='15' name='cerca' class='input' size="15" > 
   

  <input type="image" src="immagini/trova.gif"  value='Cerca'> 

        </form> 

</form> 


       <?php 

// connettiamoci il nostro database 

include 'db_connect.php'; 

//connetto il database 


// recuperiamo il valore ricerca inviato con get 

$ricerca = $_GET['ricerca']; 

// vediamo se è stato inviato, e quindi uguale a ok 

if ( $ricerca == 'ok' ) { 

// recuperiamo ora cerca inviato con post 

$cerca = $_POST['cerca']; 

// vediamo se è stato compilato il campo 

if ( $cerca == TRUE && $cerca != "" ) { 

// ora vediamo se supera i tre caratteri 

if ( strlen($cerca) >= 3 ) { 

// ora depuriamo la stringa da cercare sul database  

$cerca =  mysql_escape_string(stripslashes($cerca));  

// ora possiamo effettuare la nostra ricerca sul db, state attenti alla sintassi 

$query = "SELECT * FROM annunci WHERE titolo LIKE '%$cerca%' OR tipologia LIKE '%$cerca%'  ";  

$risultato = mysql_query($query) or die (mysql_error());  

$risposta = mysql_query($query) or die ("Utilizza termini più specifici!"); 

$dentro_la_query= mysql_fetch_assoc($risposta); 

if ( $dentro_la_query == TRUE ) { 

while($row= mysql_fetch_assoc($risultato)) {  

$id_annunci = $row['id_annunci']; 
$tipo = $row['tipologia']; 
$titolo = $row['titolo']; 

$ricerca = $row['ricerca']; 


// stampiamo i nostri dati 







echo "<a href=\"rannunci.php?id=$id_annunci\"/><h2>$titolo</h2></a><br>";  



} 

} else { 

echo "Nessun temine alla ricerca trovato"; 

} 


} else { 

echo "Devi inserire almeno 3 caratteri"; 

} 

} else { 

echo "Non hai compilato il modulo ricerca"; 

} 

} 

?>


La pagina che deve restituire i risultati è :

rannunci.php


PHP:
<?php 

require ("db_connect.php");  

$id_annunci=$_GET['id']; 


$query = mysql_query ("SELECT * FROM annunci  

        INNER JOIN cliente ON (annunci.clienteid=cliente.id)  
        INNER JOIN modello ON (annunci.modelloid=modello.id)  
        INNER JOIN risparmio ON (annunci.risparmioid=risparmio.id)  
        INNER JOIN catris ON (annunci.catrisid=catris.id)  
        INNER JOIN condizioni ON (annunci.condizioniid=condizioni.id)  
        INNER JOIN tipo ON (annunci.tipoid=tipo.id)  
        INNER JOIN notizie ON (annunci.notizieid=notizie.id ) 
        INNER JOIN categorie ON (annunci.categorieid=categorie.id) 
        INNER JOIN users ON (annunci.user_id=users.id)   
        WHERE id_annunci=$id_annunci LIMIT 1");  


if (!$query) { 
  exit('<p>Error performing query: ' . mysql_error() . '</p>'); 
} 


while ($row = mysql_fetch_array($query)) { 
$user_id = $row ['id']; 
$titolo = $row ['titolo']; 
$id_annunci = $row ['id_annunci']; 
$ts = $row ['ts']; 
$messaggio = substr($row['messaggio'], 0, 10000);  
$dotazione = substr($row['dotazione'], 0, 500);  
$strumentazione = substr($row['strumentazione'], 0, 500);  
  $telefono = substr($row['telefono'], 0, 25);  
 $modello = $row ['modello']; 
  $mq = $row ['mq']; 
    $locali = $row ['locali']; 
     $prezzo = $row ['prezzo']; 
      $tipologia = $row ['tipologia']; 
      $tipo = $row ['tipo']; 
      $altro = $row ['altro']; 
       $condizioni = $row ['condizioni']; 
      $name = $row ['name'];  
  $citta = $row ['citta']; 
  $cliente = $row ['cliente']; 
  $logo_cliente = $row ['logo_cliente']; 
  $regione = $row ['regione']; 
   $provincia = $row ['provincia']; 
    $comune = $row ['comune']; 
      $via = $row ['via']; 
       $cap = $row ['cap']; 
       $anno = $row ['anno']; 
        $societa = $row ['societa']; 
 $email = $row ['email']; 
 $nome_file = $row ['nome_file']; 
  $tipo_file = $row ['tipo_file']; 
  $dati_file = $row ['dati_file']; 
 $nome_file2 = $row ['nome_file2']; 
  $tipo_file2 = $row ['tipo_file2']; 
  $dati_file2 = $row ['dati_file2']; 
  $nome_file3 = $row ['nome_file3']; 
  $tipo_file3 = $row ['tipo_file3']; 
  $dati_file3 = $row ['dati_file3']; 
  $nome_file4 = $row ['nome_file4']; 
  $tipo_file4 = $row ['tipo_file4']; 
  $dati_file4 = $row ['dati_file4']; 
  $nome_file5 = $row ['nome_file5']; 
  $tipo_file5 = $row ['tipo_file5']; 
  $dati_file5 = $row ['dati_file5']; 
}  
?> 
 qui printo i dati 

    <td><br  /><?php echo "<p><h2><b>$titolo</h2></b></p>";?></td> 
  </tr> 
</table> 
   
  
<table width="740" height="7"> 
  <tr> 
    <td><br /><?php echo "<p><b> <h3>Data Articolo:  $anno</h3></b><br /><br /><h3><b>$tipologia</b><br /><br /></h3></p>";?></td> 
  </tr> 
  <tr> 
    <td><?php echo "<p><h4><b>$messaggio</b></h4></p>";?></td> 
  </tr> 
</table> 
<br /> 
<table width="734"> 
  <tr> 
    <td width="726" align="left" ><?php echo "<p><h4><b> Riferimento annuncio:  Obbligazioni $id_annunci</b></h4></p>";?></td> 
  </tr> 
</table> 
<br /> 
<font color="FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Note: Copia e incolla la parte [ Obbligazioni xxx ] nella form per avere una risposta immediata al tuo annuncio. </font> 
<br /> 
<hr /> 

<br /> 
<table width="100%"> 
  <tr> 
    <td align="center" valign="middle"><?php require "728x90-1.php" ; ?></td> 
  </tr> 
</table> 
<br /><table width="705"> 
  <tr>

Il problema è nella JOIN, se io printo i dati come nelle pagine e quindi con una pagina rannunci_obb ecc ecc come da codice che segue tutto bene !!!

PHP:
<?php 

require ("db_connect.php");  

$id_annunci=$_GET['id']; 

/// query originale /// 

$query = mysql_query ("SELECT * FROM 
   annunci INNER JOIN condizioni ON (annunci.condizioniid=condizioni.id)  
        INNER JOIN tipo ON (annunci.tipoid=tipo.id)  
      INNER JOIN users ON (annunci.user_id=users.id)   
       WHERE id_annunci=$id_annunci LIMIT 1");  


if (!$query) { 
  exit('<p>Error performing query: ' . mysql_error() . '</p>'); 
} 


while ($row = mysql_fetch_array($query)) { 
$user_id = $row ['id']; 
$titolo = $row ['titolo']; 
$id_annunci = $row ['id_annunci']; 
$ts = $row ['ts']; 
$messaggio = substr($row['messaggio'], 0, 10000);  
$dotazione = substr($row['dotazione'], 0, 500);  
$strumentazione = substr($row['strumentazione'], 0, 500);  
  $telefono = substr($row['telefono'], 0, 25);  
 $modello = $row ['modello']; 
  $mq = $row ['mq']; 
    $locali = $row ['locali']; 
     $prezzo = $row ['prezzo']; 
      $tipologia = $row ['tipologia']; 
      $tipo = $row ['tipo']; 
      $altro = $row ['altro']; 
       $condizioni = $row ['condizioni']; 
      $name = $row ['name'];  
  $citta = $row ['citta']; 
  $cliente = $row ['cliente']; 
  $logo_cliente = $row ['logo_cliente']; 
  $regione = $row ['regione']; 
   $provincia = $row ['provincia']; 
    $comune = $row ['comune']; 
      $via = $row ['via']; 
       $cap = $row ['cap']; 
       $anno = $row ['anno']; 
        $societa = $row ['societa']; 
 $email = $row ['email']; 
 $nome_file = $row ['nome_file']; 
  $tipo_file = $row ['tipo_file']; 
  $dati_file = $row ['dati_file']; 
 $nome_file2 = $row ['nome_file2']; 
  $tipo_file2 = $row ['tipo_file2']; 
  $dati_file2 = $row ['dati_file2']; 
  $nome_file3 = $row ['nome_file3']; 
  $tipo_file3 = $row ['tipo_file3']; 
  $dati_file3 = $row ['dati_file3']; 
  $nome_file4 = $row ['nome_file4']; 
  $tipo_file4 = $row ['tipo_file4']; 
  $dati_file4 = $row ['dati_file4']; 
  $nome_file5 = $row ['nome_file5']; 
  $tipo_file5 = $row ['tipo_file5']; 
  $dati_file5 = $row ['dati_file5']; 
}  
?>

se aggiungo le altre JOIN per avere la possibilità di printare i risutati con un'unica pagina non mi printa i dati ( pero' mi prende l'id dell'annuncio ) che cosa sbaglio ????

Grazie
 
Discussioni simili
Autore Titolo Forum Risposte Data
T [Javascript] identico carousel con effetto fade: in una pagina va in un'altra no, mistero? Javascript 3
L Mistero,Rage Extender Rotto o Cosa? Reti LAN e Wireless 18
zighy mistero !DOCTYPE HTML e CSS 0
E Mistero cavo Lan non funziona Reti LAN e Wireless 2
M Mistero: Mozilla, tutto perfetto, anomalia in Internet explorer HTML e CSS 2
borgo italia mistero di wysiwyg Javascript 2
Eliox mistero svelato Discussioni Varie 5
M Mistero con Myphp Admin PHP 0
borgo italia mistero di msql_query PHP 6
G Il mistero delle immagini fantasma HTML e CSS 37
Cforever datagrid??? mistero..... ASP.NET 2
L Soluzione con INNER JOIN Database 0
K Problema Inner join PHP 1
L Problema con inner join PHP 11
K [php] Problema con inner join PHP 4
M LEFT JOIN di diverse condizioni PHP 10
R Join articolato su 3 tabelle MySQL 5
M Join 3 tabelle PHP 0
L select join e sottrazione punti PHP 13
M Problema su query JOIN in tre tabelle PHP 0
MarcoGrazia Dati nulli su join tra più tabelle MySQL 1
M Ordinare una query join PHP 2
M Estrarre valori MAX da un db con una left join MySQL 8
P Query Mysql con Join PHP 2
S [PHP] Inner join su 4 tabelle PHP 6
M [PHP] Aiuto su inner join PHP 10
F [MySQL] Problema con LEFT JOIN MySQL 6
P [MySQL] Inner Join o Left Join MySQL 14
simgia [PHP] Ciclare una query JOIN PHP 2
simgia [MySQL] INNER JOIN problema MySQL 0
R [PHP] Estrapolare dati da una query left join PHP 0
C Php/Mysql query JOIN tra tabelle PHP 4
C Php/Mysql query JOIN tra due tabelle PHP 18
R [MySQL] SQL UPDATE INNER JOIN MySQL 5
G [MS Access] JOIN di due tabelle più GROUP BY MS Access 1
G [MySQL] Join o select MySQL 1
R [MySQL] Join, Count e Order (ASC & DESC)... MySQL 6
B Outer join che non funge Database 2
jdj78 inner join Classic ASP 18
V [Guida]: ho dubbi sulle Join MySQL 13
P Query con Somma di un Campo , aggregazione e join Database 3
V Quando mettere il JOIN e quando no? MySQL 1
L cinque tabelle e join PHP 2
P Join tabelle MySQL 4
Marco_88 Select distinct e join MySQL 2
Marco_88 Eliminare una colonna da una LEFT JOIN MySQL 4
M Query Join per 2 colonne MySQL 1
D Problema sintassi INNER JOIN a 3 tabelle PHP 4
L inner join MySQL 0
andrea.peo Problema query con join visualizzazione record ripetuti PHP 5

Discussioni simili