Reputation: 439
I am working on to create a comparison of college i almost completed It but now i want find the empty values and put a strike instead of empty column i know i can do this using if statements what i am seeking is there a better way other than using nested if else or multiple if
controller has a function to select value
public function test()
{
$insId = "INS20160738";
$course = "B.Tech Electronics & Communication Engineering";
$this->load->model('comparisonModel');
$resFirst = $this->comparisonModel->selFirst($insId,$course);
foreach ($resFirst as $key => $value) {
echo '<h6> name:</h6><p>'.$value['course_name'].'</p><h6>Duration:</h6>'.$value['duration'].'
<h6>eligiblity:</h6><p>'.$value['eligibility'].'</p><h6>recognition:</h6><p>'.$value['recognition'].'</p><h6>Affiliation:</h6>'.$value['affiliation'].'
<h6>Certification:</h6>'.$value['certificate'].'<h6>Category:</h6>'.$value['category'].'<h6>Type:</h6>'.$value['type'].'<h6>Category:</h6>'.$value['school_batch'].'';
}
}
model for the selecting is
public function selFirst($insId,$course)
{
$stmt='SELECT * FROM `institute-course` WHERE `institute-id`= '.$this->db->escape($insId).' AND `course_name`='.$this->db->escape($course);
$res=$this->db->query($stmt);
return $res->result_array();
}
i get result like this
name:
B.Tech Electronics & Communication Engineering
Duration:
eligiblity:
plus two
recognition:
Affiliation:
A P J Abdul Kalam Technological University
Certification:
B.Tech in Electronics & Communication Engineering
Category:
under graduate
Type:
college
Category:
what i searching is there a better way to get result like this
name:
B.Tech Electronics & Communication Engineering
Duration: this field is Empty or put a strike
eligiblity:
plus two
recognition:this field is empty
Affiliation:
A P J Abdul Kalam Technological University
Certification:
B.Tech in Electronics & Communication Engineering
Category:
under graduate
Type:This Is filed Is empty
college
Category: this field is empty
with out using multiple if else statements
thanks in advance
Upvotes: 0
Views: 74
Reputation: 1826
You could test if the value is empty
if (empty($value['type'])) {
$value['type'] = 'This field is empty';
}
Or if the value is NULL in the database, you can specify it in the select
- clause:
SELECT *, IFNULL(type, 'This field is empty') ...
Upvotes: 0
Reputation: 38584
In foreach loop try this (controller)
foreach ($resFirst as $value)
{
?>
<h6> name:</h6>
<p> <?= (empty($value['course_name'])) ? 'this field is empty' : $value['course_name'] ; ?> </p>
<h6> Duration:</h6>
<p> <?= (empty($value['duration'])) ? 'this field is empty' : $value['duration'] ;?> </p>
<h6> eligiblity:</h6>
<p> <?= (empty($value['eligiblity'])) ? 'this field is empty' : $value['eligiblity'] ;?> </p>
<h6> recognition:</h6>
<p> <?= (empty($value['recognition'])) ? 'this field is empty' : $value['recognition'] ;?> </p>
<h6> Affiliation:</h6>
<p> <?= (empty($value['affiliation'])) ? 'this field is empty' : $value['affiliation'] ; ?> </p>
<h6> Certification:</h6>
<p> <?= (empty($value['certificate'])) ? 'this field is empty' : $value['certificate'] ; ?> </p>
<h6> Category:</h6>
<p> <?= (empty($value['category'])) ? 'this field is empty' : $value['category'] ; ?> </p>
<h6> Type:</h6>
<p> <?= (empty($value['type'])) ? 'this field is empty' : $value['type'] ; ?> </p>
<h6> Category:</h6>
<p> <?= (empty($value['school_batch'])) ? 'this field is empty' : $value['school_batch'] ; ?> </p>
<?php
}
Upvotes: 2