<?php foreach ($category_features as $category_feature):?>
<?php if( $category_feature['form_type'] == 'text' ){?>
<div class="six wide field">
<label><?php echo $category_feature['feauture'];?></label>
<input type="text" name="name-<?php echo $category_feature['id']?>">
</div>
<?php } ?>
<?php if( $category_feature['form_type'] == 'select' ){?>
<div class="six wide field">
<label><?php echo $category_feature['feauture'];?></label>
<select name="name-<?php echo $category_feature['id']?>">
<option value="">Choose</option>
<?php foreach ($feauture_values as $feauture_value):?>
<!-- how can i get the features' values -->
<?php endforeach;?>
</select>
</div>
<?php } ?>
<?php endforeach;?>
As you see, I get the category features from a table and loop. And then a feature maybe selectbox so options are in another table. For every feature which is selectbox, I need to get that feature values which means options.. How can I create an SQL for this?
**features
id | feature | form_type
**category_features
id | feature_id | category_id
**feature_values
id | feature_value | feature_id
My tables are like that. According to category_id, I get the features. And I want to get also options if form_type is selectbox.
I think, it needs two steps to obtain the data structure that you want.
first, using the SQL like this
select
f.from_type,
f.feature,
fv.feature_id,
fv.feature_value
from features as f
inner join category_features as cf
on f.id = cf.feature_id
right join feature_values as fv;
and then aggregate the record set, maybe like following code
$result = [];
array_map(function (item) use (&$result) {
// do some aggregate operations
}, $records);
it's hard to get correct result at one time