How to handle one to many relation in PHP
<p>How do I correctly echo a one to many query result?</p>

<p>With a one table query result I would just echo each row after fetching it, for example:</p>

<pre><code>+---+------+
|ID | title|
|1  | a    |
|2  | b    |
|3  | c    |
+---+------+

$smtp-&gt;bind_result($ID, $title);
while($smtp-&gt;fetch()) {
    \\echo here                        
}
</code></pre>

<p>But after using a query with a natural join (example below), I have no idea how to echo it in PHP as: <br>"3 - c - Action, Fantasy, Military"</p>

<pre><code>+----+-------+----------+
| ID | title | genre    |
|  3 |   c   | Action   |
|  3 |   c   | Fantasy  |
|  3 |   c   | Military |
+----+-------+----------+
</code></pre>

<p>EDIT:</p>

<p>Let me rephrase the question. When using a one to many relationship, how do I properly showcase the results from the "many" table?</p>

<p>This is the code I use at the moment.</p>

<pre><code>//connect to database with self made db class object.
$db = new db();
$db = $db-&gt;connect();

$smtp = $db-&gt;prepare('select ID, title, description, genre from movie NATURAL JOIN movie_genres WHERE date &gt;= ? AND date &lt; ?');
$smtp-&gt;bind_param('ss', $seasonStart, $seasonEnd); //variables defined based on current date.
$smtp-&gt;execute();
$smtp-&gt;bind_result($ID, $title,$description, $genre));
while($smtp-&gt;fetch()) {
    echo '
    &lt;div class="upcoming"&gt;
        &lt;div id="upcomingPoster" style="background-image: url(images/' . $ID . '.jpeg)"&gt;
            &lt;div&gt;
                &lt;a href=""&gt;' . $title . '&lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="upcomingInfo"&gt;
            &lt;h2&gt;Description&lt;/h2&gt;
            &lt;p class="upcomingInfoDescription"&gt;' . $description .'&lt;/p&gt;
            &lt;div&gt;&lt;/div&gt;
            &lt;p&gt;' . $genre . '&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;';
}
</code></pre>

<p>Now when using this, my code basically loops for every row. But I am trying to put all of the genres next to each other, before it loops to the next movie. </p>