0

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

3
  • why you format code inside controller. you can do it on View easily Commented Aug 29, 2016 at 7:53
  • so that no php code inside view Commented Aug 29, 2016 at 8:01
  • Check my answer. Its works on controller. if you need to show them in view pass them and chnage foreach variable Commented Aug 29, 2016 at 8:03

2 Answers 2

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

0

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') ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.