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
https://forums.phpfreaks.com/topic/146700-help-with-array-manipulation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.