PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2002, 01:07 PM
rfigley rfigley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 87 rfigley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 27 sec
Reputation Power: 7
Alphabetizing dropdown list

I have this dropdown list as part of a form that inserts/updates to the MySQL database:

http://www.npiflorida.com/admin/cha...own2-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?:

PHP Code:
<?

 
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');


?>

Reply With Quote
  #2  
Old November 6th, 2002, 01:16 PM
persaltier's Avatar
persaltier persaltier is offline
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: NYC
Posts: 57 persaltier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 19 sec
Reputation Power: 8
Send a message via AIM to persaltier
PHP Code:
 $query=("select * from tbl_chapter order by chapter_name asc"); 


mysql select statement

Reply With Quote
  #3  
Old November 6th, 2002, 01:18 PM
cranium's Avatar
cranium cranium is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: close to the edge
Posts: 956 cranium User rank is Sergeant Major (2000 - 5000 Reputation Level)cranium User rank is Sergeant Major (2000 - 5000 Reputation Level)cranium User rank is Sergeant Major (2000 - 5000 Reputation Level)cranium User rank is Sergeant Major (2000 - 5000 Reputation Level)cranium User rank is Sergeant Major (2000 - 5000 Reputation Level)cranium User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 2 h 19 m 33 sec
Reputation Power: 32
Hi,

Or you can do the sort after you get the info out of the db with sort function.

I hope that helps,
cranium

Reply With Quote
  #4  
Old November 6th, 2002, 02:03 PM
rfigley rfigley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 87 rfigley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 27 sec
Reputation Power: 7
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.

Reply With Quote
  #5  
Old November 6th, 2002, 02:19 PM
rfigley rfigley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 87 rfigley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 27 sec
Reputation Power: 7
ok, nevermind. Figured it out. Thank you so much for your help.

Reply With Quote
  #6  
Old November 6th, 2002, 03:35 PM
rfigley rfigley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 87 rfigley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 27 sec
Reputation Power: 7
Oops. Spoke too soon. Have another Pulldown issue to resolve.

http://www.npiflorida.com/admin/cou...chapter_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:

PHP Code:
<?

 
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');


?>

Reply With Quote
  #7  
Old November 7th, 2002, 01:00 AM
ghatzhat ghatzhat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 361 ghatzhat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 5 sec
Reputation Power: 7
try
Code:
SELECT DISTINCT county FROM tbl_chapter ORDER BY county


a few other notes:

don't use * unless it makes life a lot easier - i.e. if you want 7 or 8 fields from 10 that are there, use *. if you just want one or two, call them directly. okay, so this effect is minor in most cases, but when you are joining several large tables and there's a fair bit of output it'd be wise to minimise it.

you might want to be a bit more consistent with your SQL case - so that it is obvious what is SQL and what are table names etc.

good luck.
__________________
Little more than a playground for the bugs that live beneath us...

Reply With Quote
  #8  
Old November 7th, 2002, 12:27 PM
rfigley rfigley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 87 rfigley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 27 sec
Reputation Power: 7
Thank you. Much appreciated.
Yes I agree, there are a lot of inconisistencies in my coding format which I need to clean up. Have other areas of this application needing tidying up as well.

Reply With Quote
  #9  
Old November 7th, 2002, 01:04 PM
Tzicha's Avatar
Tzicha Tzicha is offline
Here, not there
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 312 Tzicha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 36 sec
Reputation Power: 7
You can also get rid of that empty if statement, unless you are going to use it in the future.
PHP Code:
if (mysql_num_rows($result) == 0)
{

}
else
{

//The above can become
if(mysql_num_rows($result) > 0)
{

//Or even
if(mysql_num_rows($result) != 0)
{
//It all depends on what you are accomplishing of course 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Alphabetizing dropdown list


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT