简体   繁体   中英

How to get values from two columns in the same table

I have a table Students which has student_id (Pk) and two columns class_id and class_id2 as a student can be registered in two classes i would like to use Code-igniter to get the values of both columns and i tried arrays but it doesn't seem to work as it gets all students

<?php 
   $students   =   $this->db->get_where('student' , array('class_id'=>$class_id) )->result_array();
      foreach($students as $row):?>
           <tr class="gradeA">
                <td><?php echo $row['roll'];?></td>
                <td><?php echo $row['name'];?></td>
<?php 

when i change the value to class_id2 it gets the values from that column but i don't know if there is a way i can get both?

try this,

$this->db->or_where("class_id",$class_id);
$this->db->or_where("class_id2",$class_id);
$students   =   $this->db->get('student')->result_array();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM