need help on ALPHABETICAL LINKS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smileboy
Forum Newbie
Posts: 20
Joined: Wed Mar 11, 2009 6:58 am
Location: Tashkent, Uzbekistan

need help on ALPHABETICAL LINKS

Post 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
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: need help on ALPHABETICAL LINKS

Post by deejay »

where are you storing/getting the information from? ie array / database

If you could show us details of that, that may help.
smileboy
Forum Newbie
Posts: 20
Joined: Wed Mar 11, 2009 6:58 am
Location: Tashkent, Uzbekistan

Re: need help on ALPHABETICAL LINKS

Post 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
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: need help on ALPHABETICAL LINKS

Post 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.
smileboy
Forum Newbie
Posts: 20
Joined: Wed Mar 11, 2009 6:58 am
Location: Tashkent, Uzbekistan

Re: need help on ALPHABETICAL LINKS

Post 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
Post Reply