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

Alphabetical links

Post by smileboy »

point me to some php code that prints out the alphabet as links? Example:

I want it to look like this

A B C D E F G H I J and so on.

And when I click on a link I want to send a quary to mySql. If I click on C for example I want the database to give me every post that begins on the letter C, and print it out like this:

Cevin
Cumulus
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Alphabetical links

Post by susrisha »

Code: Select all

 
 
foreach(range('a','z') as $i)
 {  
    echo '<a href="">';
    echo $i;
    echo '</a>   | ';
 } 
 
This one is for displaying alphabets as hrefs only.
You need to put the href to the page and get the variable accordingly..
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Alphabetical links

Post by papa »

For the MySQL part, use SELECT, LIKE. Search on google.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Alphabetical links

Post by mattpointblank »

EG:

Code: Select all

 
$query = "SELECT * FROM table WHERE article_name LIKE '$variable%'";
 
The % sign means match anything after $variable. If $variable is 'a' then it'll match 'aardvark', 'anteater', etc.
Post Reply