RJT Posted April 20, 2006 Share Posted April 20, 2006 My database and site are nearlly complete, but i need advice and help with two things.[b]1. Ordering the List[/b]Currently my list orders alphabetically like this: (example)[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]AlAndyBeanBillBlakeCanChristian[/quote] I somehow need to code it so the database puts a space between each beginning letter like this:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]AlAndyBeanBillBlakeCanChristian[/quote]My Code is:[code]<?php include('http://www.reef-break.com/cawcenter/header.php') ?><?include("dbinfo.inc.php");mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM caws ORDER BY name";$result=mysql_query($query);$num=mysql_numrows($result); mysql_close();echo "<b><center>Viewing All CAWs ($num)</center></b><br>";?><?$i=0;while ($i < $num) {$name=mysql_result($result,$i,"name");$category=mysql_result($result,$i,"category");?><?php echo "<a href='http://www.reef-break.com/cawcenter/svr2006/caw.php?name=$name'>$name</a><br>" ?><?++$i;} ?><?php include('http://www.reef-break.com/cawcenter/footer.php') ?>[/code][b]2. Seperating Data[/b]In my add data form, there is a category option. I need to make a series of pages that will list the appropriate data for each category ($category). For Example if the category was "A" then it would only list the names that were given that category in the add data form.Sorry if that sounds confusing, the code is the same as the one in my other problem.Ive been wondering how to do these for ages, and currently have no clue. So if someone could help me out here it would be [b]greatly[/b] appreciated :) Quote Link to comment Share on other sites More sharing options...
jworisek Posted April 20, 2006 Share Posted April 20, 2006 a php solution could be something like:(untested)[code]$i=0;$first_letter_old="";while ($i < $num) {$name=mysql_result($result,$i,"name");$category=mysql_result($result,$i,"category");$first_letter=substr($name,0,1);echo "<a href='http://www.reef-break.com/cawcenter/svr2006/caw.php?name=$name'>$name</a><br>";if (($first_letter!=$first_letter_old)&&($first_letter_old!="")){ echo "<br />";}else{}$first_letter_old=$first_letter;++$i;}[/code] Quote Link to comment Share on other sites More sharing options...
RJT Posted April 20, 2006 Author Share Posted April 20, 2006 Thanks alot for that jwo :). For some reason though the first record of the next letter still ends up with the previous letter. Like this:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]AbyssAJ Styles (Green Attire)AJ Styles (Red Attire)Alex ShelleyAnimalAustin AriesBilly GunnBobby LashleyBoogeymanBrian KendrickBrock Lesnar (WWE Attire)Brother DevonBrother RayChris HarrisChris Sabin (Old Attire)Christopher DanielsChristy HemmeEddie GuerreroGoldberg (Black and White Attire)Gregory HelmsHomicideJames MitchellJames StormJeff Hardy (TNA Attire)Joey MercuryKevin Nash (TNA Attire)Monty Brown (Black Attire)Monty Brown (Red Attire)Petey WilliamsRaven (Late 2005 Attire)RhinoSabuSamoa JoeShannon MooreShark Boy (Classic Attire)Sonjay Dutt[/quote]Any suggestions? (Im new with PHP and MySQL ;) lol) Quote Link to comment Share on other sites More sharing options...
RJT Posted April 23, 2006 Author Share Posted April 23, 2006 *bump* Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 23, 2006 Share Posted April 23, 2006 [code]$i=0;$first_letter_old="";while ($i < $num) { $name=mysql_result($result,$i,"name"); $category=mysql_result($result,$i,"category"); $first_letter=substr($name,0,1); if (($first_letter!=$first_letter_old)&&($first_letter_old!="")){ echo "<br />"; } $first_letter_old=$first_letter; ++$i; echo "<a href='http://www.reef-break.com/cawcenter/svr2006/caw.php?name=$name'>$name</a><br>";} [/code] Quote Link to comment Share on other sites More sharing options...
RJT Posted April 23, 2006 Author Share Posted April 23, 2006 It works! Thanks alot AndyB & jwo :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.