Page 1 of 1

Alphabetical links

Posted: Wed Mar 18, 2009 1:13 am
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

Re: Alphabetical links

Posted: Wed Mar 18, 2009 1:46 am
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..

Re: Alphabetical links

Posted: Wed Mar 18, 2009 3:39 am
by papa
For the MySQL part, use SELECT, LIKE. Search on google.

Re: Alphabetical links

Posted: Wed Mar 18, 2009 3:49 am
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.