<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problema con inner join]]></title><description><![CDATA[<p dir="auto">Salve ragazzi. Il problema è il seguente. Ho tre tabelle, che memorizzano dati di clienti, eventi e ordini. Vi mostro la struttura. La prima, utenti:</p>
<p dir="auto">CREATE TABLE <code>utenti</code> (<br />
<code>utente_id</code> int(3) NOT NULL auto_increment,<br />
<code>username</code> varchar(30) NOT NULL default '',<br />
<code>password</code> varchar(34) NOT NULL,<br />
<code>confermapassword</code> varchar(34) NOT NULL,<br />
<code>nome</code> varchar(30) NOT NULL default '',<br />
<code>cognome</code> varchar(30) NOT NULL default '',<br />
<code>giorno</code> int(2) NOT NULL default '',<br />
<code>mese</code> int(2) NOT NULL default '',<br />
<code>anno</code> int(4) NOT NULL default '',<br />
<code>cap</code> int(10) NOT NULL default '',<br />
<code>provincia</code> varchar(30) NOT NULL default '',<br />
<code>indirizzo</code> varchar(30) NOT NULL default '',<br />
<code>civico</code> int(5) NOT NULL default '',<br />
<code>mail</code> char(255) NOT NULL default '',<br />
<code>data</code> timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,<br />
<code>ip</code> char(15) NOT NULL default '',<br />
PRIMARY KEY  (<code>utente_id</code>),<br />
UNIQUE KEY <code>id</code> (<code>utente_id</code>),<br />
KEY <code>id_2</code> (<code>utente_id</code>)<br />
)</p>
<p dir="auto">La seconda, eventi:</p>
<p dir="auto">CREATE TABLE <code>eventi</code> (<br />
<code>event_id</code> int(5) unsigned NOT NULL auto_increment,<br />
<code>evento</code> text NOT NULL,<br />
<code>luogo</code> text NOT NULL,<br />
<code>dataevento</code> varchar(50) NOT NULL default '',<br />
<code>ora</code> varchar(50) NOT NULL default '',<br />
<code>descrizione</code> text NOT NULL,<br />
<code>disponibilita</code> int(3),<br />
<code>prezzo</code> decimal (5,2),<br />
<code>autore</code> varchar(50) NOT NULL default '',<br />
<code>data</code> timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,<br />
<code>nome</code> varchar(50) NOT NULL default '',<br />
<code>size</code> varchar(25) NOT NULL default '',<br />
<code>type</code> varchar(25) NOT NULL default '',<br />
<code>immagine</code> longblob NOT NULL,<br />
<code>pub</code> int(1) NOT NULL default '0',<br />
PRIMARY KEY  (<code>event_id</code>)<br />
)</p>
<p dir="auto">La terza, ordini:<br />
CREATE TABLE <code>ordini</code> (<br />
<code>ordine_id</code> int(5) NOT NULL auto_increment,<br />
<code>utente_id</code> int(5) NOT NULL,<br />
<code>event_id</code> int(5) NOT NULL,<br />
<code>numero</code> int(5),<br />
<code>totale</code> decimal (5,2),<br />
<code>data</code> timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,<br />
PRIMARY KEY  (<code>ordine_id</code>)<br />
)</p>
<p dir="auto">Come vedete nell'ultima ho i campi che mettono in relazione le tre tabelle. In questo modo vorrei ottenere, in una pagina, tutti i dati relativi agli acquisti effettuati da un determinato utente. Ad esempio, l'utente 1 che eventi ha acquistato, quanti biglietti per singolo evento, il costo totale. La query sarebbe questa, ma da un problema.</p>
<pre><code class="language-php">&lt;?php 
include("config.php");  
mysql_connect($db_host,$db_user,$db_password,$db_name) or die ("non riesco a connettermi");  
mysql_select_db("$db_name") or die ("Non riesco a selezionare il database");  
if(empty($_GET["id"])){ 
echo"Non hai selezionato nulla"; 
} 
else{ 

$dati = mysql_query("SELECT utenti.*, eventi.*, ordini.*  
FROM utenti 
INNER JOIN ordini ON ordini.utente_id = utenti.utente_id 
INNER JOIN eventi ON eventi.event_id = ordini.event_id 
WHERE utenti.utente_id ='".$_GET['id']."'") or die( mysql_error() . "&lt;br&gt;" . $sql); 
$array = mysql_fetch_array($dati); 

echo "&lt;h3&gt;Evento acquistato&lt;/h3&gt; $array[evento]&lt;br&gt;&lt;br&gt;";  
echo "&lt;h3&gt;Biglietti acquistati&lt;/h3&gt; $array[numero]&lt;br&gt;&lt;br&gt;";  
echo "&lt;h3&gt;Costo totale:&lt;/h3&gt; $array[totale]&lt;br&gt;"; 
echo "Acquistato il ".substr($array ['dataora'],0,10)." alle ". substr($array ['dataora'],11,5); 
mysql_close(); 
} 
?&gt;
</code></pre>
<p dir="auto">Il problema è semplice, l'esecuzione di questa query mi da solo un risultato, il primo acquisto effettuato da un determinato utente. Dal primo in poi nulla. Esce fuori solo il primo, gli altri eventualmente fatti è come se non esistano all'interno del database. Come mai? Io vorrei che uscisse fuori la lista di tutti gli ordini effettuati, con nome e cognome dell'utente, la sua via, numero civico, eventi acquistati, numero biglietti per singolo evento, totale costo dei biglietti acquistati per ogni singolo evento.</p>
<p dir="auto">Perchè non salta fuori, dove sto sbagliando?</p>
]]></description><link>https://dev.connect.gt/topic/65179/problema-con-inner-join</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 16:49:36 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/65179.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Mar 2008 08:43:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problema con inner join on Wed, 05 Mar 2008 10:46:42 GMT]]></title><description><![CDATA[<p dir="auto">Il problema della query l'ho risolto.<br />
Piuttosto, all'interno della query</p>
<p dir="auto">SELECT utenti.<em>, eventi.evento as strEvento, ordini.</em><br />
FROM utenti<br />
INNER JOIN ordini ON ordini.utente_id = utenti.utente_id<br />
INNER JOIN eventi ON eventi.event_id = ordini.event_id<br />
WHERE utenti.utente_id ='".$_GET['id']."' Order by ordine_id Desc LIMIT $primo, $per_page"</p>
<p dir="auto">vorrei inserire la stringa</p>
<p dir="auto">date_format(data,'%d-%m-%Y %H:%i') AS 'dataora'</p>
<p dir="auto">ma non c'è verso!! Ho provato in vari modi ma nulla. Come posso fare?</p>
]]></description><link>https://dev.connect.gt/post/690347</link><guid isPermaLink="true">https://dev.connect.gt/post/690347</guid><dc:creator><![CDATA[marckh]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:46:42 GMT</pubDate></item><item><title><![CDATA[Reply to Problema con inner join on Wed, 05 Mar 2008 09:00:04 GMT]]></title><description><![CDATA[<p dir="auto">Ciao,<br />
non sono sicuro, gli inner join sono un po' duri da digerire, ma prova cosi FROM (ordini INNER JOIN utenti ON ordini.utent_id = utenti.utente_id) INNER JOIN eventi ON ordini.eventi_id = eventi.eventi_id;, cioè mettendo delle parentesi sul primo inner join</p>
]]></description><link>https://dev.connect.gt/post/690346</link><guid isPermaLink="true">https://dev.connect.gt/post/690346</guid><dc:creator><![CDATA[kalten]]></dc:creator><pubDate>Wed, 05 Mar 2008 09:00:04 GMT</pubDate></item></channel></rss>