PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
rfigley
Forum Commoner
Posts: 70 Joined: Sun Apr 21, 2002 7:10 pm
Post
by rfigley » Wed Nov 06, 2002 12:06 pm
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');
?>
cavey
Forum Newbie
Posts: 4 Joined: Wed Oct 30, 2002 12:50 pm
Post
by cavey » Wed Nov 06, 2002 12:15 pm
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.
Last edited by
cavey on Wed Nov 06, 2002 12:16 pm, edited 1 time in total.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Nov 06, 2002 12:15 pm
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
rfigley
Forum Commoner
Posts: 70 Joined: Sun Apr 21, 2002 7:10 pm
Post
by rfigley » Wed Nov 06, 2002 1:04 pm
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.
rfigley
Forum Commoner
Posts: 70 Joined: Sun Apr 21, 2002 7:10 pm
Post
by rfigley » Wed Nov 06, 2002 1:16 pm
OK, nevermind, figured it out. Thank you so much for your help
rfigley
Forum Commoner
Posts: 70 Joined: Sun Apr 21, 2002 7:10 pm
Post
by rfigley » Wed Nov 06, 2002 2:34 pm
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
<?
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 "<B> Current Chapters List </B>";
echo "<select name='county'>";
while($row = mysql_fetch_array($result))
{
$county = $rowї'county'];
echo "<option>" . "$county" . "</option>";
}
}
//$chapter = $chapter_name;
//include ('display_chapter_.php');
?>