title: Paginate while ignoring sub rows, with a Right Join
body: <p>I have this basic query that returns a main row of a program title(eventdesc) and then lists program participants and info as multiple sub rows.</p>
  
  <p>PROGRAM 1<br>
  Email 1, email 2, name, status (first participant)<br>
  Email 1, email 2, name, status (second participant)<br>
  PROGRAM 2<br>
  Email 1, Email 2, name, status (first participant)  </p>
  
  <p>ETC...</p>
  
  <p>Basic query:</p>
  
  <pre><code>$query_perpage = "SELECT COUNT(*) FROM camps_events";
  $result = mysql_query($query_perpage, $db) or die(mysql_error());
  $r = mysql_fetch_row($result);
  $numrows = $r[0];
  
  
  $pages = new Paginator($query);
  $pages-&gt;items_total = $numrows;
  $pages-&gt;paginate();
  $pages-&gt;mid_range = 7;
  
  
  $query = mysql_query("SELECT ce.eventcode, ce.eventdesc, ce.date, r.participant_fname, r.participant_lname, 
  r.position, r.dob, r.status, r.email_primary, r.order_number 
  FROM camps_events ce 
  RIGHT JOIN registrations r on r.eventcode = ce.eventcode 
  WHERE ce.reg_status = 'Active' 
  AND r.status NOT IN ('Incomplete','Canceled')".getAllowedPrograms()." 
  ORDER BY ce.eventdesc, ce.eventcode, r.participant_lname ASC $pages-&gt;limit ") or die(mysql_error());
  </code></pre>
  
  <p>I've been trying to figure out how to paginate it by Program, no matter how many subrows.
  I have a pagination class in place on another page, but that only pulls from one table.</p>
  
  <p>I've been trying to implement the same pagination, but I can only get it to pull the first program, and then it limits the page based on the sub rows, not the main program row. And in the state I've posted it here, each following page displays only the first programs. The sub rows that come up are different on each page, but I can't tell if they are all in the first program.</p>
  
  <p>The query works fine for pulling all results properly, but if it's a huge list, it's extremely inefficient, and can even timeout the browser.</p>
  
  <p>Any help would be much appreciated, please let me know if I can include anything else.</p>
  
  <p>I'm not too concerned with using the same pagination class, so I'm completely open to different approaches.</p>
  
  <p>Thanks in advance</p>