Page 1 of 1

Alphabetizing dropdown list

Posted: Wed Nov 06, 2002 12:06 pm
by rfigley
I have this dropdown list as part of a form that inserts/updates to the MySQL database:

http://www.npiflorida.com/admin/chapter ... member.php

I'm trying to alphabetize the list and have a selected one showing first, here is the code I'm using. Would I have to retrieve the list into and array to sort it?:

Code: Select all

<?

 include('dbconnect.php');
 include('font_setting2.htm');

 $query = ("select * from tbl_chapter");

$result = mysql_query($query) or die("Query fail");

if (mysql_num_rows($result) == 0)
{

} else
{

   //echo "<B> Current Chapters List </B>";
     echo  "<select name='chapter'>";
     echo "<option>" . "$chapter_name" . "</option>";
  while($row = mysql_fetch_array($result))
    {
	 
        $chapter_name = $rowї'chapter_name'];

        echo "<option>" . "$chapter_name" . "</option>";
           }

}

 include ('chapter_for_delete2.php');


?>

Posted: Wed Nov 06, 2002 12:15 pm
by cavey
how about:

select * from tbl_chapter ORDER BY chapter_name

also, you do not have to select all the fields (*) if you only need chapter_name.

Posted: Wed Nov 06, 2002 12:15 pm
by volka
try

Code: Select all

SELECT * FROM tbl_chapter ORDER BY chapter_name
<option selected="true">option-text</option> preselectes one entry of an dropdown <select>-element

Posted: Wed Nov 06, 2002 1:04 pm
by rfigley
OK, that was easy, thanks.

Also as mentioned but was probably not clear is the need to have a currently selected chapter displayed. HEre's the page tha this is part of:

http://www.npiflorida.com/admin/update_member.php
THis is the last page that they come to to update a member's data. It normally displays all their data from the database including the chapter. Need their current chapter to show in the field, but have the ability to select one if the member is changing chapters.

Posted: Wed Nov 06, 2002 1:16 pm
by rfigley
OK, nevermind, figured it out. Thank you so much for your help

Posted: Wed Nov 06, 2002 2:34 pm
by rfigley
Oops. Spoke too soon. Have another Pulldown issue to resolve.

http://www.npiflorida.com/admin/county_ ... er_add.php

Need to eliminate duplicate returns in result. Attempting as you see to use DISTINCTROW, have tried that and DISTINCT. What am I doing wrong?

Using this code:

Code: Select all

&lt;?

 include('dbconnect.php');
 include('font_setting2.htm');

 $query = ("select DISTINCTROW * from tbl_chapter order by county");

$result = mysql_query($query) or die("Query fail");

if (mysql_num_rows($result) == 0)
{

} else
{

   //echo "&lt;B&gt; Current Chapters List &lt;/B&gt;";
     echo  "&lt;select name='county'&gt;";


  while($row = mysql_fetch_array($result))
    {
        $county = $row&#1111;'county'];

        echo "&lt;option&gt;" . "$county" . "&lt;/option&gt;";
           }

}

  //$chapter = $chapter_name;
 //include ('display_chapter_.php');


?&gt;