dimanche 19 juin 2016

Compare 2 Tables and show dropdown selected (20 dropdowns)- PHP - Mysql

I have written a Query which pulls data from table mytable.

I am trying to show the dropdowns selected depending on the value in another table.

Another table name is lnkTable (the 2 table are not linked, so have to compare the name in both tables to show value selected) which has 20 columns (split1, split2, .. split20)

Shall i write second tables while loop in <?php foreach ($result as $row): ?>, how do I compare and show selected

<?php

    // FIRST TABLE TO SHOW DROP DOWN VALUES Run your query once and store the results

    $plan_sql = "select id, name from mytable";
    $plan_res = mysqli_query($con, $plan_sql);
    while ($row = mysqli_fetch_array($plan_res, MYSQLI_ASSOC)) {
        $result[] = $row;
    };

// SECOND TABLE TO SHOW THE DROP DOWN VALUES SELECTED

 $plan_sql1 = "select name from lnkTable WHERE id='".$MY_id."' ";

    $plan_res1 = mysqli_query($con, $plan_sql1);
    while ($row = mysqli_fetch_array($plan_res1, MYSQLI_ASSOC)) {
        $result[] = $row;
    };


    // sHOW ALL DROP DOWNS FROM FIRST TABLE 

    for ($i=1; $i <= 20; $i++):?>
    <div class="form-group">
        <label>Split <?php echo $i; ?></label>
        <select class="form-control required" name='distance[]' id='distance' >
            <option value="-1">Select Distance</option>
            <?php foreach ($result as $row): ?>
                <option value="<?php echo $row['id'];?>"><?php echo $row['name'];?></option>
            <?php endforeach ?>
        </select>
    </div>
    <?php endfor; ?> 

Aucun commentaire:

Enregistrer un commentaire