RE: [PHP] categorise list
> I am dispalying data from mysql database using the codes below: > > $while($row=mysql_fetch_array($result)) > { > echo $row[name]; > } > > How can i format the above data in this format as shown below? in > alphabetical order > > A > -- > -click to go up > Apple > Armchair > > B > -- > -click to go up > Basket > Baseball You need an "ORDER BY name" in your query to get the results sorted alphabetically, first. Then, as you loop through the results, you need to "remember" the current letter you're on. If the letter changes, then output the header and line showing the next letter. Something like this: $old_letter = ''; $query = "SELECT name FROM table ORDER BY name"; $rs = mysql_query($query); while($row = mysql_fetch_assoc($rs)) { $current_letter = strtoupper(substr($row['name'],0,1)); if($current_letter != $old_letter) { echo "$current_letter\n"; $old_letter = $current_letter; } echo $row['name'] . ''; } Untested... adapt to your needs. Oh, add in your "go to top" link, also. ---John W. Holmes... Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] categorise list
$letter=''; $while($row=mysql_fetch_array($result)) { if($letter!=$row[name][0]) { echo $row[name][0].''; $letter=$row[name][0]; } echo $row[name].''; } Op maandag 09 juni 2003 12:41, schreef u: > I am dispalying data from mysql database using the codes below: > > $while($row=mysql_fetch_array($result)) > { > echo $row[name]; > } > > How can i format the above data in this format as shown below? in > alphabetical order > > A > --- >click to go up Apple > Armchair > > B > --- >click to go up Basket > Baseball > > C > --- >click to go up Car > > > > and so on > > > any suggestions?? > > Many thanks, > awlad > > ___ > > Sheridan Phoenix Company > The Business Centre Kimpton Road Luton Bedfordshire LU2 0LB > > Email: [EMAIL PROTECTED] > Phone: 01582 522 330 > Fax:01582 522 328 > ___ > > This electronic transmission is strictly confidential and intended > solely for the addressee. If you are not the intended addressee, you > must not disclose, copy or take any action in reliance of this > transmission. If you have received this transmission in error it would > be helpful if you could notify The Sheridan Phoenix Company Ltd as soon > as possible. > > Any views expressed in this message are those of the individual sender, > except where the sender specifically states them to be the views of The > Sheridan Phoenix Company Ltd. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] categorise list
I am dispalying data from mysql database using the codes below: $while($row=mysql_fetch_array($result)) { echo $row[name]; } How can i format the above data in this format as shown below? in alphabetical order A ---click to go up Apple Armchair B ---click to go up Basket Baseball C ---click to go up Car and so on any suggestions?? Many thanks, awlad ___ Sheridan Phoenix Company The Business Centre Kimpton Road Luton Bedfordshire LU2 0LB Email: [EMAIL PROTECTED] Phone: 01582 522 330 Fax:01582 522 328 ___ This electronic transmission is strictly confidential and intended solely for the addressee. If you are not the intended addressee, you must not disclose, copy or take any action in reliance of this transmission. If you have received this transmission in error it would be helpful if you could notify The Sheridan Phoenix Company Ltd as soon as possible. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of The Sheridan Phoenix Company Ltd.