Stom Posted February 24, 2009 Share Posted February 24, 2009 Hello all, and thanks in advance for helping an idiot... I have a website for an art gallery. There is a page with a list all the artists that exhibit. Curerntly the listen orders them alphabetically. As there is only one field in the database for the artist's name, they are all ordered by their first name. I'd like to change it so that they are ordered by surname and i'm not sure the easiest way to go about it. Also, some of the artists have "RSW" and other such acronyms after their names so i'd need a way to account for this. Current code below: <?php $artistsresults = mysql_query("SELECT * FROM artists WHERE atoz='1' ORDER BY name") or die('Query failed: ' . mysql_error()); while ($artist=mysql_fetch_array($artistsresults)) { $artists[]=substr($artist['name'], 0, 1); } $artistlist=array_unique($artists); ?> <br style="clear:both;" /> <a name="top"><h3 style="display:none;">List of Artists</h3></a> <ul style="list-style:none;padding:0;margin:0;"> <?php foreach ($artistlist as $artistl) { echo '<li> <a class="thumbnail" name="'.$artistl.'">'.$artistl.'</a></li>'; $listartists = mysql_query("SELECT * FROM artists WHERE name LIKE '".$artistl."%' AND atoz='1' ORDER BY name") or die('Query failed: ' . mysql_error()); echo '<ul style="list-style:none;">'; while ($listartist=mysql_fetch_array($listartists)) { echo '<li><a class="thumbnail" href="artists.php?id='.$listartist['id'].'#portfolio" onclick="javascript:void();">'.$listartist['name'].'<span><img src="images/artworks/'.$listartist['sample'].'/preview.jpg" /></span></a></li>'; } echo '</ul>'; } ?> </ul> Thanks to all the respond Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted February 24, 2009 Share Posted February 24, 2009 Difficult. You may be better adding a surname field to the database and writing a script that will break the name up and update name and surname. Add a new field for surname on any forms that insert into the table Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.