Jump to content

PHP driven drop-down box


circus.fire

Recommended Posts

Hello all-I am very new to this so here it goes...

I am using the code below to populate a drop-down list.  Problem is that the table it's pulling from has duplicates, any idea how to get these duplicates to not show up in the list?  The DB is currently in Access and I am trying to move it over-so it's already populated.  Thanks!

 

function dept_cnumDropDown(){

echo '<select name="Dept_CourseNumber" id="Dept_CnumBox";>';

$result = db_query("SELECT Dept_Cnum FROM coursepack_info ORDER BY Dept_Cnum ASC");

    if(db_num_rows($result)) {

      while ($row = db_fetch_array($result))

      {

          echo '<option value="'.$row['Dept_Cnum'].'" class="drop_down">'.$row['Dept_Cnum'].'</option>';

      }

    } else {

      echo "<option value=''>There are no Department/Course Numbers currently listed</option>";

    }

echo '</select>';

}

 

if(!empty($_REQUEST['btnSubmit'])) {

echo 'they hit the button';

}

?>

Link to comment
https://forums.phpfreaks.com/topic/167005-php-driven-drop-down-box/
Share on other sites

$result = db_query("SELECT Dept_Cnum FROM coursepack_info ORDER BY Dept_Cnum ASC");

 

Try the following query:

 

$result = db_query("SELECT DISTINCT Dept_Cnum FROM coursepack_info ORDER BY Dept_Cnum ASC");

 

EDIT:  Now that I read your post, I'm not sure what your asking.  Could you possibly post an example from you Database?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.