title: php mysql query query :D
body: <p>This question has two parts. An answer to either part would be great :D</p>
  
  <p>1) I am using one table to store links between values of another table. I am then searching through that table to find inheritance lists.</p>
  
  <pre><code>while($cont) {
          $rst = DB::query("SELECT parentID FROM code_inheritance WHERE childID=".$sid);
          if($rst-&gt;num_rows != 0) {
              $ob = $rst-&gt;fetch_object();
              if($list != '') $list .= ',';
              $list .= $ob-&gt;parentID;
              $sid = $ob-&gt;parentID;
          } else $cont = false;
      }
  </code></pre>
  
  <p>DB is my database class.
  However, this isn't a very efficient way of searching a database. Can anyone point me in a direction where I can do this in one database query please?</p>
  
  <p>2) I then use the list to search for the names of the classes so that I can echo an inheritance list to the screen, however they are returned in ID numerical order I want them to be in the order they were found in part 1. I am currently doing this:</p>
  
  <pre><code>if($list != '') {
          $rst = DB::query("SELECT Name FROM code WHERE ID IN ($list)");
          $list = '';
          while($ob = $rst-&gt;fetch_object()) {
              echo $ob-&gt;Name;
              if($list != '') $list .= ' -&gt; ';
              $list .= '&lt;a href="/code/'.$ob-&gt;Name.'/"&gt;'.$ob-&gt;Name.'&lt;/a&gt;';
          }
          $list = "Inheritance -&gt; ".$list;
      }
  </code></pre>
  
  <p>How can I get then list in the order I found them in part one so that the inheritance tree is in the correct order?</p>
  
  <p>Sorry that this was a bit lengthy but I wanted to add as much information as I could.</p>