I have saved some values as comma separated in table 1 column.
I want to fetch all rows containing values from table 2 where these comma separated values are.
But my current code is fetching only one row with first value.
Tables structure is like below :
Table 1
id | faculties | another_field
1 | DFGHFGD1,ERTGDFGE2 | xyzxyzxyz
Table 2
id | unique_id | full_name
1 | DFGHFGD1 | AAA AAA
2 | THOGHFGD1 | BBB BBB
3 | ERTGDFGE2 | CCC CCC
4 | LLMNBHUH1 | DDD DDD
5 | HGFGDHHD3 | EEE EEE
6 | RGDJHFGN4 | FFF FFF
7 | PLYHTGGD1 | HHH HHH
Now I want to fetch both rows with unique_id = DFGHFGD1 And ERTGDFGE2 in Table 2.
I tried following code. But it is fetching only first value(DFGHFGD1) row.
<?php
$faculty ="DFGHFGD1,ERTGDFGE2"; // Fetch with another query for table 1
$var = explode(",", $faculty );
?>
<ol>
<?php
foreach($var as $value){
$fquery = "select * from table_2 where unique_id = '$value'";
$result = $database->get_results($fquery);
foreach($result as $data){
?>
<li><?php echo $data['full_name'];?></li>
<?php } ?>
</ol>
<?php } ?>
Result should be like
- AAA AAA
- CCC CCC
But I am Getting only
- AAA AAA
and
and tried just now but same result – darshan May 04 '20 at 11:40