简体   繁体   中英

How to display name instead of the id?

在此处输入图片说明

I have problem, I don't know how to display the name of the department or program instead of their id. I am currently editing the user information but when I look to the department, the one who display it's id Here's my code for the editing:

<div class="col-md-3 col-sm-3 col-xs-6 form-group has-feedback">
<label class="control-label col-md-7 col-sm-3 col-xs-12">Program</label>
        <select name="progid" class="select2_group form-control"  style="text-align:center;" >
//this part will calling the id
           <option><?php echo $rows['progid']; ?></option>
            <?php                                                   include('../connection/connect.php');
                $result = $db->prepare("SELECT * FROM program");
                $result->bindParam(':progid', $res);
                $result->execute();
            for($i=0; $row = $result->fetch(); $i++){
                echo "<option value='".$row['progid']."'>".$row['prog_name']."</option>";
                }
                    ?>
                    </select>
               </div>

In your option tags you can set the attribute value to the value you want to sumbit to the next page via the form. This could be the ID for example. Between the tags you can add any textual content you like. This will then be displayed at the dropdown.

 <form> <select name="dropdown"> <option value="id-1">Value1</option> <option value="id-2">Value2</option> <option value="id-3">Value3</option> </select> </form> 

The one ID which shows up in your department dropdown (7003) comes from this line:

<option><?php echo $rows['progid']; ?></option>

You either need to delete it and include it in your for loop or need to adapt to the previous example I have provided.

If I understand the question correctly:

In your code there is this line (line 5):

   <option><?php echo $rows['progid']; ?></option>

progId printed from here. remove this line or replace with progName.

If don't know how to find the prgname, you must find it from DB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM