Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Combining 3 Tables with Inner Join
<?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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!