简体   繁体   中英

fetch data from database and display in dropdown list

I try to fetch the data from database and display them in drop down list, but the display does not appear, and it doesn't show any error.

Why does the list of the semester not appear?

Semester:   <select name='sem_id' id='sem_id'>
                <option value="" selected> -----</option>
    <?php
        $sql = mysql_query("SELECT * FROM semdate ORDER BY sem_id DESC");

        while($row0=mysql_fetch_array($sql))
        {
                    if (($row0['sem_id'])=='131401') {
                      $cursem = "SEM 1 2013/2014";
                      $semid = '131401';
                    }

                    if (($row0['sem_id'])=='131402') {
                      $cursem = "SEM 2 2013/2014";
                      $semid = '131402';
                    }

                      if (($row0['sem_id'])=='131403') {
                      $cursem = "SEM 3 2013/2014";
                      $semid = '131403';
                    }

                      if (($row0['sem_id'])=='121303') {
                      $cursem = "SEM 3 2012/2013";
                      $semid = '121303';
                     }

        echo "<option value='".$semid."'>".$cursem.'</option>';

        }
     ?>
            </select>

 <br><br><input type='submit' name= 'hit' value ='ASSIGN to Supervisor'></form>
 <br></fieldset></form></center><br><br>

You need share more information, first, I suggest to check your query as:

$sql = mysql_query("SELECT * FROM semdate ORDER BY sem_id DESC") or die(mysql_error()) ;

With this last function, your code will die if you have a database error.

All your syntax it's ok, but I can't see if:

  • You are connected to database before with mysql_connect()
  • What columns have your table, and if your table exists.

Normally, I use "or die(mysql_error())" on each mysql function to check if works when I don't found the problem, remember remove it in production.

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