homepage Welcome to WebmasterWorld Guest from 23.20.61.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
mysql alphabetical pagination
letters work but what about number and symbols
antriver

5+ Year Member



 
Msg#: 3536647 posted 9:31 pm on Dec 28, 2007 (gmt 0)

Hi,
I've got a database full of songs for people to request on my site. I've got alphabetical pagination working fine but I also want a page for artists that start with a number or a symbol instead of a letter.

Here's the code...

if (!isset($_GET['letter'])) {$letter = "A";} else {$letter = $_GET['letter'];}
echo '<div align="center"><b>';
for ($i=65; $i<90; $i++) {
if ($letter!= chr($i)) {echo '<a href="index.php?letter='.chr($i).'">';}
echo chr($i)."&nbsp;";
if ($letter!= chr($i)) {echo '</a>';}
}
echo "</b></div><p>";

$query="SELECT * FROM songs WHERE artist LIKE '".$letter."%'";

So I just want to add one link before A B C.... for everything that isn't a letter

Thanks in advance :)

 

borntobeweb

5+ Year Member



 
Msg#: 3536647 posted 8:50 pm on Dec 29, 2007 (gmt 0)

Welcome to WebmasterWorld antriver.

You can use either the MySQL function ASCII or SUBSTRING to do this. So to fetch all artists whose name doesn't start with an alpha character:

$query="SELECT * FROM songs WHERE ASCII(UPPER(artist)) NOT BETWEEN ASCII('A') and ASCII('Z')";

or

$query="SELECT * FROM songs WHERE UPPER(SUBSTRING(artist,1,1)) NOT BETWEEN 'A' and 'Z'";

Hope this helps.

antriver

5+ Year Member



 
Msg#: 3536647 posted 7:55 pm on Dec 31, 2007 (gmt 0)

thanks, that works great :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved