title: echo out image in mysql while loop not working?
body: <p>i have a message type system set up and i am using a mysql while loop to echo out the contents from my table and am also trying to echo out the users profile image so that it appears next to each result being echoed. since this is a 2 way message system their is the photo of 'to_user_id'/recipient and 'from_user_id'/sender. this are coded as $photo and $photo2</p>
  
  <p>its all working fine, the images are coming out as they should for each result being echoed by the while loop, however and for some reason, the first result is not echoing out the image, just the div container </p>
  
  <p>does anyone know why this is. heres my code, thanks.</p>
  
  <pre><code>&lt;div class="message_field"&gt;
  &lt;div class="inner_frame"&gt;   
  
  &lt;?
  $query_for_result=mysql_query("SELECT *
                          FROM ptb_messages
                          WHERE msg_id like '%".$query."%'");
                          $inbox_set = get_inbox();
  while($data_fetch=mysql_fetch_array($query_for_result))
  if (isset($_SESSION['user_id'])) { 
  if ($data_fetch['from_user_id'] == $_SESSION['user_id']){
  
  {
  
  
  $photo = "data/photos/{$data_fetch['from_user_id']}/_default.jpg";
  if (!file_exists($photo)) {
      $photo = "data/photos/0/_default.jpg";
  
  
  } 
  
  
  $photo2 = "data/photos/{$data_fetch['to_user_id']}/_default.jpg";
  if (!file_exists($photo2)) {
      $photo2 = "data/photos/0/_default.jpg";
  
  
  } 
  
  
  
  ?&gt;
  
  
  &lt;div class="message_bubble2"&gt;
  &lt;div class="msg_bubble_img"&gt;&lt;a href=\"profile.php?id={$inbox['id']}\"&gt;&lt;img src="&lt;?php echo $photo ?&gt;" width="40" heigh="40" border="0"&gt;&lt;/a&gt;&lt;/div&gt;&lt;?php echo "".$data_fetch['content']."";?&gt;&lt;div class="message_bubble_tail2"&gt;&lt;/div&gt;&lt;div class="message_bubble_tail2_shadow"&gt;&lt;/div&gt;&lt;div class="message_bubble_tail2_shadow_bottom"&gt;&lt;/div&gt;&lt;div class="message_bubble_tail2_outline"&gt;&lt;/div&gt;
  &lt;div class="message_bubble_footer2"&gt;
  &lt;?php
  $inbox_set = get_inbox();
  while ($inbox = mysql_fetch_array($inbox_set)) { ?&gt;
  &lt;?php echo "".$review_from."";  ?&gt;&amp;nbsp;&lt;?
  $datetime1 = new DateTime();
  $datetime2 = new DateTime ($reviews['date_added']);
  $interval = $datetime1-&gt;diff($datetime2);
  $mdhms = explode('-',$interval-&gt;format('%m-%d-%H-%i-%s'));
  $labels = Array(' months', ' days', ' hours', ' minutes', ' seconds');
  $i = 0;
  foreach($mdhms as $t){
    if($t &gt; 0) break;
    $i+=1;
  }
  echo "sent by you ".$t.$labels[$i]." ago"; } ?&gt;
  &lt;/div&gt;&lt;/div&gt;
  
  
  &lt;? 
  }
  }else{
  
  
  if (isset($_SESSION['user_id'])) { 
  if ($data_fetch['from_user_id'] !== $_SESSION['user_id']){
  
  {
  
  ?&gt;  
  
  
  &lt;div class="message_bubble"&gt;&lt;div class="msg_bubble_img2"&gt;&lt;a href=\"profile.php?id={$inbox['id']}\"&gt;&lt;img src="&lt;?php echo $photo2 ?&gt;" width="40" heigh="40" border="0"&gt;&lt;/a&gt;&lt;/div&gt;&lt;?php echo "".$data_fetch['content']."";?&gt;&lt;div class="message_bubble_tail"&gt;&lt;/div&gt;&lt;div class="message_bubble_tail_shadow"&gt;&lt;/div&gt;&lt;div class="message_bubble_tail_shadow_bottom"&gt;&lt;/div&gt;&lt;div class="message_bubble_tail_outline"&gt;&lt;/div&gt;
  &lt;div class="message_bubble_footer"&gt;
  &lt;?php
  $inbox_set = get_inbox();
  while ($inbox = mysql_fetch_array($inbox_set)) { ?&gt;
  &lt;?php echo "".$review_from."";  ?&gt;&amp;nbsp;&lt;?
  $datetime1 = new DateTime();
  $datetime2 = new DateTime ($reviews['date_added']);
  $interval = $datetime1-&gt;diff($datetime2);
  $mdhms = explode('-',$interval-&gt;format('%m-%d-%H-%i-%s'));
  $labels = Array(' months', ' days', ' hours', ' minutes', ' seconds');
  $i = 0;
  foreach($mdhms as $t){
    if($t &gt; 0) break;
    $i+=1;
  }
  echo "sent from ".$inbox['from_user_id']." ".$t.$labels[$i]." ago"; } ?&gt;
  &lt;/div&gt;&lt;/div&gt;
  
  
  &lt;? } } } } } ?&gt;
  </code></pre>