title: SQL/PHP I have the start and end locations but want to find the joining legs from a table
body: <p>I have a problem looping through my <code>tableLegs</code> for a bus timetable to find the array of legs <code>legID</code> that the passenger would need to take to get from a to b, take for example the passenger want to start at <code>LocID</code> of <code>c</code> and travel to <code>LocID</code> of <code>p</code>, I would like the array of legs that make up that trip <code>LegID</code>'s (<code>01</code>, <code>02</code>, <code>04</code>), hope that is easy enough to follow.</p>
  
  <p><strong>tableLegs</strong></p>
  
  <pre><code>=============================================
  LegID    startLocID   endLocID   departTime
   01          a           e        9:00
   02          e           i        10:00
   03          i           m        11:00
   04          i           q        11:00
  </code></pre>
  
  <p><strong>tableLegStops</strong></p>
  
  <pre><code>=========================================
  LegID     stopNo    LocID     TripTime
    01         1         a       0 min
    01         2         b       20 min
    01         3         c       30 min
    01         4         d       40 min
    01         5         e       60 min
    02         1         e       0 min
    02         2         f       20 min
    02         3         g       30 min
    02         4         h       40 min
    02         5         i       60 min
    03         1         i       0 min
    03         2         j       20 min
    03         3         k       30 min
    03         4         l       40 min
    03         5         m       60 min
    04         1         i       0 min
    04         2         n       20 min
    04         3         o       30 min
    04         4         p       40 min
    04         5         q       60 min
  </code></pre>
  
  <p>To give you a basis for what I am trying to achieve here, it's for a bus website where each trip is made up of different legs.</p>