I have 2 tables: Events and Registration.
Events Fields: EventID and EventName
Registration Field: MemberID and Name
I want to pull the EventName and the Name- of the person. How do I do this with a model?
The code I have:
Model
function getAll()
{
$query = $this->db->get('tblRegistration');
if( $query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
}
$query->free_result();
return $data;
}
controller
public function getallevents() {
$this->load->model('events_model');
$data['records'] = $this->events_model->getAll();
$this->load->view('view-events', $data);
}
View
foreach ($records as $row):
echo "<tr>";
echo "<td> $row->Name</td>";
// echo "<td> $row->intLocationID</td>";
echo "</tr>";
endforeach;
Edit
OK I have added the data that I want out of the table.
model
function getAll()
{
// get all the records from the schools table
$this->db->select('*');
$this->db->from('tblRegistration as reg');
$this->db->join('tblMeetRace as met', 'reg.intMeetRaceID = met.intEventID');
$query = $this->db->get();
// if the number of rows returned is more than 0
if( $query->num_rows() > 0) {
// loop through each record (row) and place that
// record into an array called $data
foreach ($query->result() as $row) {
$data[] = $row;
}
}
$query->free_result();
// return the array to the controller
return $data;
}
view
foreach ($records as $row):
echo "<tr>";
echo "<td> $row->intMeetRaceID/td>";
echo "<td> $row->intEventID</td>";
echo "</tr>";
endforeach;
but I get an error of:
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/view-events.php
Line Number: 89