title: Unnexpected item-comments depending on query of items
body: <p>I am using this function to list items from table <code>helps</code> depending on parameters: (I included most of code but you can really just focus on the mysql querys)</p>
  
  <pre><code>function list_helps($by,$value,$page = -1,$ipp = 20){
      /* Yes I concatenate querys... so i use some variables to help it a bit */
      $sql = 'SELECT helps.* FROM helps ';
      $where = ''; $orderBy = ''; $in = ''; $join = ''; $limit = '';  $resultitems = ''; $header = '';
      if($page &gt; 0)   $limit = 'LIMIT '.$page*$ipp.', '.($page+1)*$ipp; else $limit = 'LIMIT 10';
      switch($by){
  
          case 'byuser':
              $where = 'WHERE id_user ='.$value;
              $orderBy = 'ORDER BY id DESC';
              break;
          case 'byfriend':
              $sql = 'SELECT
                h.*,
                f.* 
              FROM (
                SELECT
                  id,
                  CASE followerid WHEN '.$value.' THEN followingid ELSE followerid END AS friend_id
                FROM friends
                WHERE acepted = 1
                  AND (followerid  = '.$value.' OR followingid = '.$value.')
              ) AS f
                INNER JOIN helps AS h ON h.id_user = f.friend_id
                ORDER BY h.id DESC';
              break;
          default:
              break;
      }
      $sql .= $where.' '.$orderBy.' '.$limit;
      $res = cache_query($sql,'',60*60*5);
      /* checks in cache first, if not; executes query.. next code it's to render content */
  }
  </code></pre>
  
  <p>There are more cases but lets focus on those two.</p>
  
  <p>They both serve the 'helps' that are being requested (if user, or if users's friend); The problem is when i am trying to retrieve the comments of those (like if it where a blog post); which I am doing like so:</p>
  
  <pre><code>res = cache_query('SELECT help_replies.content, help_replies.date, 
              help_replies.offers, help_replies.accepted, help_replies.id_responds,
              usuarios.first_name, usuarios.last_name, usuarios.avatar,usuarios.id
          FROM help_replies left join usuarios 
              ON  help_replies.id_user = usuarios.id
          WHERE  help_replies.id_responds = '.$this-&gt;id.' 
          ORDER BY help_replies.id ASC', '', 30);
  
  foreach($res as $obj) {
      /* $obj['id_responds'] */
      }
  }
  </code></pre>
  
  <p>The thing is that the <code>help_replies.id_responds</code> makes reference to the item, so when the case is 'byuser' is fine; but when the case is 'byfriend' this field is lost (so is showing always the same comments)</p>
  
  <p>Conclusion:</p>
  
  <ul>
  <li>byuser -> helps fine &amp; comments fine</li>
  <li>byfriend -> helps fine (which is wierd) &amp; comments wrong</li>
  </ul>
  
  <p>Any Idea why $this->id is not as expected from the (JOINED) query?</p>
  
  <p>-EDIT-</p>
  
  <p>$this->id comes from this construct method (i ommited many atributes)</p>
  
  <pre><code>function __construct($item) {
      $this-&gt;id = $item['id'];
      $this-&gt;id_user = $item['id_user'];
      ..  
  }
  </code></pre>
  
  <p>And $item is one iteration of the foreach (so its the returned row converted to array)</p>
  
  <p>Muchas Gracias</p>