Welcome Guest, Not a member yet? Register   Sign In
Getting data from multiple tables
#2

[eluser]gtech[/eluser]
if you wanted to keep the database as is you could do somthing like (ITS UNTESTSED, just to give you a concept)

Code:
..
  function get_xml_data()
  {
    $this->db->select();
    $this->db->from('venue');
    $this->db->join('event','event.venueID = venue.venueID');
    $this->db->join('event_day','event.eventID = event_day.eventID','right');
    $this->db->where('event.dateEnd >= current_date');
    $this->db->orderby("eventType","asc");
    $dbres =  $this->db->get();

    // [edit] add missing ;
    $retarr = array();
    // build up an events array
    // [<eventid>][<num>][<sql fieldname from join>]

    foreach ($dbres->result_array() as $key => $value) {
      if (!defined($retarr[$dbres[$key]['eventID']])) {
        // [edit] add missing ;
        $retarr[$dbres[$key]['eventID']] = array();
      }
      // [] will append to the array i.e [<event id>][0], [<event id>][1] etc
      $retarr[$dbres[$key]['eventID']][] = $dbres[$key];
    }
    return $retarr;  
  }
?&gt;

then in the view

Code:
&lt;?php foreach($xml as $eventid => $eventrows_array): ?&gt;
  echo "EVENT =: ".$eventid."BR";
  &lt;?php foreach($eventrows_array as $key => $dbrow): ?&gt;
     echo "DAY = $dbrow['day']"
  &lt;?php endforeach; ?&gt;
&lt;?php endforeach; ?&gt;

Is eventid unique in the events table? if not then maybee the database design needs a bit of thought.

If eventID is not unique in the events table, is it because you have a many2many relationship between events & venues (e.g. a venue can have many events, and an event can have many venues) or between events & event_days?

If this is the case then maybe you should have a lookup table between the many2many relationship so you can keep the eventID unique in the events table to save you having to replicate data.


Messages In This Thread
Getting data from multiple tables - by El Forum - 11-13-2007, 07:58 PM
Getting data from multiple tables - by El Forum - 11-14-2007, 04:16 AM
Getting data from multiple tables - by El Forum - 11-14-2007, 03:26 PM
Getting data from multiple tables - by El Forum - 11-14-2007, 04:52 PM
Getting data from multiple tables - by El Forum - 11-15-2007, 02:15 AM
Getting data from multiple tables - by El Forum - 11-15-2007, 02:49 AM
Getting data from multiple tables - by El Forum - 11-27-2007, 07:03 PM
Getting data from multiple tables - by El Forum - 11-28-2007, 08:37 AM
Getting data from multiple tables - by El Forum - 11-28-2007, 04:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB