Doubt to get the id of a different Php and Mysql table

Asked

Viewed 165 times

0

How do I save the id of a different table within a select ?

Code below

<div class="medium">
            <span>
                <select name="turma">
                    <option>Selecione a Sala</option>
                    <?php
                    do {
                        ?>
                        <option> <?php echo $exibe['sala'] ?> </option>
                    <?php } while ($exibe = mysql_fetch_assoc($sql)) ?>
                </select>
                <span class="icon-place"></span>
            </span>
        </div>

Class is a different table, the complete form is for the registration of a student!

  • 2

    That depends on your query if she has left Join to class

1 answer

1

Put the option value with the class id. Not seeing the bank is difficult, but I suppose it is so:

<option value="<?php echo $exibe['id_turma'] ?>"> <?php echo $exibe['sala'] ?> </option>

I also suggest you use the while instead of do while

<select name="turma">
    <option>Selecione a Sala</option>
    <?php
    while ($exibe = mysql_fetch_assoc($sql)) { ?>
        <option value="<?php echo $exibe['id_turma'] ?>"> <?php echo $exibe['sala'] ?> </option>
    <?php } ?>
</select>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.