Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda