title: Mysql select multiple queries inside eachother
body: <p>I am having some trouble with selecting data from my database using data from a previous select. What I want to do is. First I let mysql select all vechiles from my database from the table vechiles. I echo them and inside the while loop I try to select the picture for the vechile from a diffrent table by select the picture with the vechile_id:</p>
  
  <p>Now my first question is. Is this the right way to do it? I assume there must be a more neat way but I cant find how.</p>
  
  <pre><code>    &lt;?php
              $sql = "SELECT id, brand FROM vechiles";
              $result = $conn-&gt;query($sql);
  
              if ($result-&gt;num_rows &gt; 0) {
                  while($row = $result-&gt;fetch_assoc()) {
  
                      $sql1 = "SELECT * FROM fotos WHERE vechiles_id =". $row['id'];
                      $result1 = $conn-&gt;query($sql1);
  
                      echo '&lt;li&gt;&lt;p class="title"&gt;'. $row['brand'] .'&lt;/p&gt;
                              &lt;p class="type"&gt;type: 2387&lt;/p&gt;
                              &lt;p class="ez"&gt;ez: 1987&lt;/p&gt;';
  
                              if ($result1-&gt;num_rows &gt; 0) {
                               // output data of each row
                              while($row1 = $result1-&gt;fetch_assoc()) {
                                  echo '&lt;img src="admin/'. $row1['url'] .'" atl="tractor 1"/&gt;';
                              }}else{
                                  echo "there are no pictures";
                              }
  
                              echo '&lt;div class="info"&gt;
                              &lt;p class="prijs"&gt;Prijs: 1800,- EX BTW&lt;/p&gt;
                              &lt;p class="msg"&gt; Prijzen onder voorgehoud&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;a class="button" href="#"&gt;Meer info&lt;/a&gt;&lt;/li&gt;';
                  }
              } else {
                  echo "0 results";
              }
              $conn-&gt;close();
          ?&gt;
  </code></pre>
  
  <p>Noe the above example works fine but I want to only select the first picture instead of all uploaded pictures.
  So to this code:</p>
  
  <pre><code> $sql1 = "SELECT * FROM fotos WHERE voertuig_id =". $row['id'];
  </code></pre>
  
  <p>I added</p>
  
  <pre><code> $sql1 = "SELECT TOP 1 * FROM fotos WHERE voertuig_id =". $row['id'];
  </code></pre>
  
  <p>And I also tried</p>
  
  <pre><code> $sql1 = "SELECT * FROM fotos WHERE voertuig_id =". $row['id'] . "LIMIT 1";
  </code></pre>
  
  <p>But when I do that it suddenly says there are no pictures. What am I doing wrong!</p>
  
  <p>appreciate all the help!</p>