1

There should be 2 dropdownlist.

1st dropdownlist is filled with data from database "videoname" 2nd dropdownbox is filled with data from database "video_id"

when user select the 1st dropdownbox the 2nd dropdownbox will be display the corresponding data accordingly. How should i do that?

example user click lesson 1 on the 1st dropdownbox. the 2nd dropdownbox will display video_id 1

the data will be pass to another php file using form.

     <?php

                // save information into database
                $username = "root";
                $password = "";
                $hostname = "localhost"; 
                $dbname = "test_database";

                //connect to the database
                $dbc = mysqli_connect($hostname, $username, $password, $dbname) or die ("could not connect to the database");

                //$sql = "SELECT video_id, videoname FROM viewvideo";

                //echo $sql;

                $result = mysqli_query($dbc, "SELECT video_id, videoname FROM viewvideo");              

                ?> 
                <form action="viewvideo.php" method="post" >
                <br/>
                Please select the video
                <br/>

                <select>
    <?php
         while($row = mysqli_fetch_array($result)){
    ?>       
          <option value="<?php echo $row['video_id']?>">
             <?php echo $row['videoname']?>
          </option>         
    <?php
         }
    ?>
</select>

enter image description here

Mick Jack
  • 550
  • 1
  • 5
  • 21
  • You are missing open parenthesis after while `while($row = mysqli_fetch_row($result)) {` – Thamilhan Jan 20 '16 at 06:49
  • Check this article to understand how to build dependent selexboxes: http://www.sanwebe.com/2013/05/select-box-change-dependent-options-dynamically, also you can reffer to articles posted in answer: http://stackoverflow.com/questions/30262313/php-auto-update-selectbox-based-on-1st-selectbox – Armen Jan 20 '16 at 07:17

1 Answers1

0

HI you can do this way

//db connection
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);

//query
$sql=mysql_query("SELECT video_id, videoname FROM viewvideo");
if(mysql_num_rows($sql)){
$select= '<select name="select">';
while($rs=mysql_fetch_array($sql)){
      $select.='<option value="'.$rs['video_id'].'">'.$rs['videoname'].'</option>';
  }
}
$select.='</select>';
echo $select;