<?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[JOIN Query MySQL]]></title><description><![CDATA[<p dir="auto">Buona sera a tutti GTiani,<br />
mi rivolgo a voi perchè nonostante le innumerevoli spiegazioni trovate non sono arrivato ad un risultato funzionante<img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--x" style="height:1.4em;width:auto;vertical-align:middle" title=":x:" alt="❌" />x:x</p>
<p dir="auto">Ciò di cui ho bisogno è di costruire una query per la sezione "Blog" del mio sito web che mi consenta di estrarre informazioni da più tabelle (senza effettuare, quindi, più query).<br />
Credo che il metodo più efficiente siano le JOIN QUERY, tuttavia non riesco ad effettuarle.<br />
LE TABELLE</p>
<p dir="auto"><strong>CATEGORIE</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>cat_id</th>
<th>cat_title</th>
<th>cat_desc</th>
</tr>
</thead>
<tbody>
<tr>
<td>ID della categoria</td>
<td>Il mio titolo</td>
<td>La mia descrizione</td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>POST</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>post_id</th>
<th>post_title</th>
<th>post_text</th>
<th>post_aut</th>
<th>post_cat</th>
</tr>
</thead>
<tbody>
<tr>
<td>ID del post</td>
<td>Il mio titolo</td>
<td>Il contenuto del post</td>
<td>ID dell'autore</td>
<td>ID della categoria</td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>AUTORI</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>aut_id</th>
<th>aut_first_name</th>
<th>aut_last_name</th>
<th>aut_email</th>
</tr>
</thead>
<tbody>
<tr>
<td>ID dell'autore</td>
<td>Nome autore</td>
<td>Cognome autore</td>
<td>Email dell'autore</td>
</tr>
</tbody>
</table>
<p dir="auto">Quello che ho bisogno è di ottenere tutti questi dati in una sola query cosi da poterli mostrare nella schermata di riepilogo dei post con il classico</p>
<pre><code class="language-php">// Inizializzo la variabile
$lista_post = ''; 

// Estraggo i dati dalla query e genero l'HTML
while($row = mysqli_fetch_array($result)) { 
  $lista_post .= '&lt;li&gt;Titolo: '.$row["post_title"].', Autore:  '.$row["aut_first_name"].', Categoria di riferimento:  '.$row["post_cat"].'&lt;/li&gt;';
} 

// Mostro l'HTML generato
echo $list_post;
</code></pre>
<p dir="auto">Qualcuno può aiutarmi? Grazie mille!<br />
Un saluto<img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/54a3bffb-5e4a-4eb8-81dc-99b2072e5d05-175.gif?v=12b9555a9a1" class="not-responsive emoji emoji-customizations emoji--ciauz" style="height:1.4em;width:auto;vertical-align:middle" title=":ciauz:" alt="" />,<br />
Francesco</p>
]]></description><link>https://dev.connect.gt/topic/214975/join-query-mysql</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 21:05:42 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/214975.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Jun 2015 16:35:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to JOIN Query MySQL on Tue, 16 Jun 2015 09:16:12 GMT]]></title><description><![CDATA[<p dir="auto">Ciao <strong>Shad!</strong><br />
Grazie mille della risposta! Ho utilizzato la tua formulazione ed ha funzionato alla perfezione. Di seguito (lo scrivo per eventuali altri interessati) il codice che ho utilizzato:</p>
<pre><code class="language-php">//connect: 
$link = mysqli_connect($host, $user, $password, $db) or die("Errore di connessione al database: &lt;br&gt;" . mysqli_error($link));   
  
//consultation: 
$query = "            
SELECT *             
FROM POST            
JOIN CATEGORIE            
ON POST.ID_CATEGORIA= CATEGORIE.ID_CATEGORIA            
JOIN AUTORI            
ON POST.ID_AUTORE= AUTORI.ID_AUTORE            
ORDER BY POST.DATA_CREAZIONE DESC"                                     
or die("Errore nella query: &lt;br&gt;" . mysqli_error($link));     

//execute the query. 
$result = $link-&gt;query($query) or die("Errore nell'esequzione della query: &lt;br&gt;" . mysqli_error($link)); ; 

// create empty var
$lista_post = '';

// fill created var with HTML
while($row = mysqli_fetch_array($result)) { 
         $lista_post .= '&lt;li&gt;Titolo: '.$row["post_title"].', Autore:  '.$row["aut_first_name"].', Categoria di riferimento:  '.$row["post_cat"].'&lt;/li&gt;';
}

// display HTML
echo $lista_post;
</code></pre>
]]></description><link>https://dev.connect.gt/post/1201467</link><guid isPermaLink="true">https://dev.connect.gt/post/1201467</guid><dc:creator><![CDATA[frabanca]]></dc:creator><pubDate>Tue, 16 Jun 2015 09:16:12 GMT</pubDate></item><item><title><![CDATA[Reply to JOIN Query MySQL on Tue, 16 Jun 2015 08:40:13 GMT]]></title><description><![CDATA[<p dir="auto">Ciao Francesco,<br />
prova così o qualcosa di simile (scusa ma non posso testare il codice adesso, quindi vado ad occhio):</p>
<pre><code>SELECT * FROM POST 
JOIN CATEGORIE ON POST.post_cat = CATEGORIE.cat_id
JOIN AUTORI ON POST.post_aut = AUTORI.aut_id
</code></pre>
<p dir="auto">Fammi sapere.<br />
Saluti</p>
]]></description><link>https://dev.connect.gt/post/1201464</link><guid isPermaLink="true">https://dev.connect.gt/post/1201464</guid><dc:creator><![CDATA[shad]]></dc:creator><pubDate>Tue, 16 Jun 2015 08:40:13 GMT</pubDate></item></channel></rss>