Jump to content

Help with array manipulation


Stom

Recommended Posts

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.