title: Displaying an image using a php variable
body: <p>I'm trying to display images by taking their file path from an sql table, but i'm having a lot of troubles.</p>
  
  <p>Here is whats going on:</p>
  
  <p><code>$image</code> is a variable containing the text <code>"itemimg/hyuna.png"</code> which is path to an image.</p>
  
  <pre><code>$image = 'itemimg/hyuna.png';
  </code></pre>
  
  <p>I assumed I would be able to display the image outside of the php block like so:</p>
  
  <pre><code>&lt;img src= "&lt;? $image ?&gt;" alt="test"/&gt;
  </code></pre>
  
  <p>This doesn't work though for some reason.</p>
  
  <p>So I thought maybe it's not able to read the variable outside the php block(i'm a beginner), so for testing i did:</p>
  
  <pre><code>&lt;h1&gt; "&lt;? $image ?&gt;" &lt;/h1&gt;
  </code></pre>
  
  <p>It displays <code>itemimg/hyuna.png</code> as a h1 banner.</p>
  
  <p>Meaning it's accessing the varible fine.</p>
  
  <p>So I thought maybe the path is wrong. So I tried:</p>
  
  <pre><code>&lt;img src= "itemimg/hyuna.png" alt="test"/&gt;
  </code></pre>
  
  <p>This displays the image perfectly.</p>
  
  <p>So now I'm stuck scratching my head why the first bit of code displays nothing but the text <code>"test"</code> from <code>"alt="</code></p>
  
  <p><strong>Extra question:</strong>
  How do I go about assigning a value from an sql cell to a variable?
  I attempted the following with no luck:</p>
  
  <pre><code>$q = "select * from item where id=$id";
  $results = mysql_query($q);
  $row = mysql_fetch_array($results, MYSQL_ASSOC);
  $image = ".$row['image'].";
  </code></pre>
  
  <p><code>item</code> is a table with a collumn: <code>image</code> which contains file paths to images</p>