Jump to content


Photo

Two problems


  • Please log in to reply
5 replies to this topic

#1 RJT

RJT
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 April 2006 - 05:16 PM

My database and site are nearlly complete, but i need advice and help with two things.

1. Ordering the List
Currently my list orders alphabetically like this: (example)

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Al
Andy
Bean
Bill
Blake
Can
Christian
[/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--]
Al
Andy

Bean
Bill
Blake

Can
Christian
[/quote]

My Code is:

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


2. Seperating Data
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 greatly appreciated :)

#2 jworisek

jworisek
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 20 April 2006 - 05:43 PM

a php solution could be something like:
(untested)
$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;
}





#3 RJT

RJT
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 April 2006 - 05:59 PM

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--]Abyss
AJ Styles (Green Attire)
AJ Styles (Red Attire)
Alex Shelley
Animal
Austin Aries
Billy Gunn

Bobby Lashley
Boogeyman
Brian Kendrick
Brock Lesnar (WWE Attire)
Brother Devon
Brother Ray
Chris Harris

Chris Sabin (Old Attire)
Christopher Daniels
Christy Hemme
Eddie Guerrero

Goldberg (Black and White Attire)

Gregory Helms
Homicide

James Mitchell

James Storm
Jeff Hardy (TNA Attire)
Joey Mercury
Kevin Nash (TNA Attire)

Monty Brown (Black Attire)

Monty Brown (Red Attire)
Petey Williams

Raven (Late 2005 Attire)

Rhino
Sabu

Samoa Joe
Shannon Moore
Shark Boy (Classic Attire)
Sonjay Dutt[/quote]

Any suggestions? (Im new with PHP and MySQL ;) lol)

#4 RJT

RJT
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 23 April 2006 - 05:08 PM

*bump*

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 April 2006 - 05:51 PM

$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>";
}

Legend has it that reading the manual never killed anyone.
My site

#6 RJT

RJT
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 23 April 2006 - 07:29 PM

It works! Thanks alot AndyB & jwo :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users