Query veloce veloce...

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Ciao a tutti...
In questa query,
PHP:
SELECT * FROM oggetti WHERE id LIKE '%$txt%' ORDER BY id DESC
Vado a prendere i campi della tabella oggetti che hanno 'id' = a XXX e li ordina.
Se volessi aggiungere nella lista anche i risultati del campo id_venditore = a XXX?
Dove XXX è lo stesso valore per entrambi...

Pensavo a una cosa del genere ma non mi funziona...
PHP:
SELECT * FROM oggetti WHERE id LIKE '%$txt%' AND id_venditore LIKE '%$txt%' ORDER BY id DESC

Dove sbaglio????
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Ciao,
con AND deve soddisfare entrambe le condizioni
sostituiscilo con OR
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
ma perche non dovrebbe funzionare con l'AND?
dato che usa il like %tex% se in text ad es c'è "9" dovrebbe turare fuiri tutti i record in cui nell'id c'è un 9 e nell'id_venditore lo stesso
es.
1139336 225587 (non estratto)
1166992 589673 (estrato)

con l'OR li estrae entrambi
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Così mi funziona...
PHP:
SELECT * FROM oggetti WHERE id LIKE '$txt' OR id_venditore LIKE '$txt' OR venduto_a LIKE '$txt' ORDER BY nome DESC

Se ci metto AND, no.
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
PHP:
SELECT * FROM oggetti WHERE id LIKE '$txt' OR id_venditore LIKE '$txt' OR venduto_a LIKE '$txt' ORDER BY nome DESC

Volevo anche dividerli, ma non riesco. Mettendo
PHP:
ORDER BY nome DESC
mi mette il risultato di "ID" all'inizio e va bene... ma mi mischia gli altri due risultati... Si può elencare prima "id_venditore" e poi "venduto_a"?
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
PHP:
<?php 
include_once ("config.php");  
include_once ("connect.php");  

$txt = $_POST['txt'];
$result = mysql_query("SELECT * FROM oggetti WHERE id LIKE '$txt' OR id_venditore LIKE '$txt' OR venduto_a LIKE '$txt' ORDER BY nome DESC");
$num=mysql_numrows($result);
 

echo "<table align='center' bgcolor='yellow' border='1' height='' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr> 
<th align='center'>Cod.Id</th>
<th align='center'>Data</th>
<th align='center'>Nome</th>
<th align='center'>Cognome</th>
<th align='center'>Descrizione</th>
<th align='center'>Prezzo</th>
<th align='center'>Q.ta'</th>
<th align='center'>%</th>
<th align='center'>Ha venduto</th>
<th align='center'>Ha comprato</th>
<th align='center'>Stato</th>
<th align='center'>data vendita</th>
<th align='center'>Stato</th>
<th align='center'>data rimborso</th>
</tr>"; 
 
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
    echo "<tr>
    <td align='center'><a href=\"modifica_oggetti.php?mod=$id\"><input style='color:black;background-color:#33FF33;' type='submit' value='".$row['id']."'></a></td>
    <td align='center'>".$row['data']."</td>
    <td align='center'>".$row['nome']."</td>
    <td align='center'>".$row['cognome']."</td>
    <td align='center'>".$row['descrizione']."</td>
    <td align='center'>".$row['prezzo']."</td>
    <td align='center'>".$row['quantita']."</td>
    <td align='center'>".$row['percento']."</td>
    <td align='center'>".$row['id_venditore']."</td>
    <td align='center'>".$row['venduto_a']."</td>
    <td align='center'>".$row['venduto']."</td>
    <td align='center'>".$row['data_vendita']."</td> 
	<td align='center'>".$row['pagamento']."</td>
	<td align='center'>".$row['data_rimborso']."</td></tr>";
     
        
}  
echo "Oggetti $num<br>\n";
echo "</table>"; 

?>
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Ma a me così non va...
PHP:
("SELECT * FROM oggetti WHERE id LIKE '$txt' OR id_venditore LIKE '$txt' OR venduto_a LIKE '$txt' ORDER BY nome, id_venditore, venduo_a")
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Ho risolto così...
PHP:
"SELECT * FROM oggetti WHERE id LIKE '$txt' OR id_venditore LIKE '$txt' OR venduto_a LIKE '$txt' ORDER BY venduto_a='$txt' , id_venditore='$txt' , id='$txt'"
 
Discussioni simili
Autore Titolo Forum Risposte Data
max75 query su due tabelle e dati doppioni MS Access 2
E Aiuto per query PHP 8
E Query differenza tra tabelle MySQL 5
E Query Alias PHP 4
T Query con date MS Access 1
K Inserimento query Errore 1366 PHP 4
L Query e selezione DB con $_POST PHP 2
M query update e delete PHP 0
A media degli elementi estratti da una query MySQL 0
S Passare query o utm alla pagina successiva Domini 1
O problema con query PHP 4
M Query PHP 8
R query DELETE non cancella i record PHP 1
G Query con i giorni della settimana MySQL 10
E Query annidate o cicli MySQL 1
C bottone query MySQL 0
T Query su due tabelle con totali Database 4
G AVVISO QUERY IN ESECUZIONE PHP 1
M Riportare in tabella HTML dati estratti con query SQL MySQL 0
S Selezionare ultimo record di una sotto query MySQL 27
G Menù a tendina di ricerca con query PHP 1
V Query per una somma PHP 2
F stampare a video i risultati della query PHP 1
L problema con query select PHP 2
D Query sum Database 1
M Visualizzazione a video risultati query php PHP 0
A form PHP prenotazione tramite query PHP 2
R Problema query con ricerca id numerico PHP 2
G Casella combinata in una query MS Access 4
R Aiuto con le query MS Access 2
Y query di DELETE PHP 4
V Query Oracle Oracle 0
L query somma PHP 8
W Query SQL Classic ASP 2
M Problemi con query a più tabelle PHP 3
Alex_70 Conteggio nella query PHP 0
elpirata Query per leggere dati da una tabella mysql e mostrarli a video in base a parametri passati tramite GET PHP 5
A nome file che contiene punto passato come parametro a query PHP 31
F query e form con select multipla PHP 17
M Problema su query JOIN in tre tabelle PHP 0
M Ordinare una query join PHP 2
Alex_70 Query ORDER BY PHP 18
G Problema ------- con Query PHP 1
G Problema con Query PHP 1
Alex_70 foreach explode query PHP 3
O query con date in formato stringa PHP 3
Tommy03 Unione query di 4 tabelle MySQL 1
I Fatal error: Query Failed! SQL: SELECT * INTO OUTFILE PHP 1
Alex_70 Query group actor e film PHP 26
TpD Incolonnare risultati query (mysql_result deprecato...) PHP 3

Discussioni simili