Page 1 of 1

need help on ALPHABETICAL LINKS

Posted: Tue Mar 31, 2009 8:30 am
by smileboy
hi, i wanted to make alphabetical list as links
i have this php code so far to display alphabetical list

Code: Select all

 
<?php
foreach (range('a', 'z') as $letter)
{
echo $letter;
}
?>
 
but i want those letters to be links and when i click "A" for example, it should show all records starts with "A"

can anyone help me on dis

thanx

Re: need help on ALPHABETICAL LINKS

Posted: Tue Mar 31, 2009 9:06 am
by deejay
where are you storing/getting the information from? ie array / database

If you could show us details of that, that may help.

Re: need help on ALPHABETICAL LINKS

Posted: Tue Mar 31, 2009 9:17 am
by smileboy
thanx 4 reply deejay

my data is stored in MySQL database
in database i've two tables 'title' and 'words'

in 'title' i've two fields for 'id' and 'word'

in 'words' i've 'id', 'title', 'description', 'example', 'user'

as i have several reocords under same title in table 'words' i've made table 'title'

so what i want is, to make alphabetical links and when i click a letter it show all the records in table 'title' which begins with that letter

hope i could explain it

Re: need help on ALPHABETICAL LINKS

Posted: Wed Apr 01, 2009 2:34 am
by deejay
here's a real quick answer, so it's just an attempt at sending you in the right direction, hopefully.

the following code will iterate through the alphabet

Code: Select all

 
<?php
for ($i="A"; $i != "AA"; $i++) echo "$i<br>";
?>
 
an easy way to do the next bit would be to build your links so that they open a mysql query that uses something along the lines of

Code: Select all

WHERE words LIKE '$i%"

hope you get the idea anyway.

Re: need help on ALPHABETICAL LINKS

Posted: Wed Apr 01, 2009 8:16 am
by smileboy
hi, thanks for ur advice
i've played around WHERE and LIKE and found some useful info using google and everything is working as i wanted

if somebody else is havin' dis kind of problem here is my code. Hope it helps!

in index.php i've dis to display alphabet as link

Code: Select all

 
<?php
foreach (range('a', 'z') as $letter)
{
      echo '<a href="[color=#0000FF]az.php[/color]?category='.$letter.'">'.$letter.'</a> ';
}
?>
 
in az.php, there is:

Code: Select all

 
<?PHP
//here goes ur connection   
$word = mysql_query("SELECT * FROM [color=#0000FF]words[/color] WHERE [color=#0000FF]title[/color] LIKE '".mysql_real_escape_string($_GET[category])."' '%' ") or die (mysql_error());
while ($row = mysql_fetch_assoc($word)) 
{
       echo $row[[color=#0000FF]title[/color]].'<br>';
} 
?>
 
highlighted words are those that u need to change

thanks for ur advice deejay