[eluser]zebake[/eluser]
Hello, new to CI and have limited php experience. I am attempting to write a student directory database application for my son's school. I have watched the tutorials and read up on the user guide. I have setup a mysql database and thanks to the video tutorials, I am able to retrieve and display the information fine. The problem I have run into is the occasional situation where a child may have two separate households (divorced parents). In this event, I need to print the information for both households. I have setup the database with the extra / alternate fields and populated them with info. How do I print the alternate contact info only if it exists, and not print anything otherwise?
This is my model:
Code:
<?php
class Student_directory_model extends Model {
function Student_directory_model()
{
// Call the Model constructor
parent::Model();
}
function getData()
{
//Query the data table for every record and row
$query = $this->db->get('students');
if ($query->num_rows() == 0)
{
//show_error('Database is empty!');
}else{
return $query->result();
}
}
}
?>
This is my view:
Code:
<html>
<head>
<title><?=$page_title?></title>
</head>
<body>
<h1><?=$page_title?></h1>
<ul>
<?php foreach($result as $row):?>
<li>
<ul>
<li><?=$row->student_lname?></li>
<li><?=$row->student_fname?></li>
<li><?=$row->phone?></li>
<li><?=$row->parents?></li>
<li><?=$row->street?></li>
<li><?=$row->city?></li>
<li><?=$row->state?></li>
<li><?=$row->zip?></li>
<li><?=$row->email1?></li>
<li><?=$row->cell?></li>
</ul>
</li>
<!-- li BELOW TO BE SHOWN ONLY WHEN NEEDED -->
<li>
<ul>
<li><?=$row->parents_alt?></li>
<li><?=$row->phone_alt?></li>
<li><?=$row->street_alt?></li>
<li><?=$row->city_alt?></li>
<li><?=$row->state_alt?></li>
<li><?=$row->zip_alt?></li>
<li><?=$row->email1_alt?></li>
<li><?=$row->cell_alt?></li>
</ul>
</li>
<?php endforeach;?>
</ul>
</body>
</html>
And this is my controller:
Code:
<?php
class Student_directory extends Controller{
function Student_directory()
{
parent::Controller();
$this->load->scaffolding('students');
}
function index()
{
$this->load->model('student_directory_model');
$data['result'] = $this->student_directory_model->getData();
$data['page_title'] = "Student Directory";
$this->load->view('student_directory_view',$data);
}
}
?>
Thanks in advance for any direction or assistance you might can provide!