• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
no output display in dropdown list

#6
(10-11-2018, 04:35 AM)kvanaraj Wrote:
Code:
<select name="staff" id="staff" required>
<option value="">Select Staff</option>
<?php

while($row_subject = mysql_fetch_array($query_subject)) {
?>
<option value="<?php echo $row_subject['deo_code'];?>  
($this->input->post('staff') == $row_subject['deo_code'] ? ' selected' : '') ><?php echo $row_subject['deo_code']."-".$row_subject['deo_name'];?></option>
<?php } ?>
</select>

I believe the problem is you don't actually do anything with the ternary statement.
Maybe the code that follows will work.

Note that I'm using PHP Alternative Syntax for control structures and the shorhand syntax for echo, e.g.<?php echo $something; is the same as <?= $something;

PHP Code:
<select name="staff" id="staff" required>
 
   <option value="">Select Staff</option>
 
   <?php
    while 
($row_subject mysql_fetch_array($query_subject)) :
 
       $sel $this->input->post('staff') == $row_subject['deo_code'] ? ' selected' NULL;
 
       ?>
        <option value='<?= $row_subject['deo_code']; ?>'
        <?php
        if
(isset($sel))
 
       {
 
           echo $sel;
 
       }
 
       echo $row_subject['deo_code']."-".$row_subject['deo_name'];
 
       ?>
    </option>
<?php endwhile; ?>
</select> 

My questions are:
Why are you using mysql_fetch_array() in a CodeIgniter project?
Do you know that the MySQL extension of PHP is deprecated? mysql_fetch_array() is from that extension.
Why are you making database calls in a view? These should be happening in a model utilized in a controller.
Do you know it's poor practice to call a function in a loop as you do with while($row_subject = mysql_fetch_array($query_subject)) ?
Reply


Messages In This Thread
no output display in dropdown list - by kvanaraj - 10-11-2018, 04:35 AM
RE: no output display in dropdown list - by Piotr - 10-11-2018, 08:20 AM
RE: no output display in dropdown list - by Piotr - 10-11-2018, 11:40 AM
RE: no output display in dropdown list - by dave friend - 10-11-2018, 11:41 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.