Links to sort fetched mysql data
Posted: Tue Sep 08, 2009 12:38 am
Hello Everyone,
I am making a long list of artists.
I generated the Alphabet, with links (A, B, C, D etc). so the people can easily find them by their last name. When I click on the letters I am getting the results ok but also the first person even when I click Z, or even when there are no artists in that letter. Could you help to do this better? also, how can I add a "No artists found" when I have no info in that letter?
I would appreciate any help. Thanks in advance!!!
Leon
Here's my code:
I am making a long list of artists.
I generated the Alphabet, with links (A, B, C, D etc). so the people can easily find them by their last name. When I click on the letters I am getting the results ok but also the first person even when I click Z, or even when there are no artists in that letter. Could you help to do this better? also, how can I add a "No artists found" when I have no info in that letter?
I would appreciate any help. Thanks in advance!!!
Leon
Here's my code:
Code: Select all
<?php
// Here is where I generate the Alphabet, with links that ends in ?letter=
for ($i=65;$i<=90; ) {
$x = chr($i);
echo '<a href="'.$_SERVER["PHP_SELF"].'?letter='.$x.'">'.$x.'</a> '."\n";
}
// This is where i get the letter from the URL
$letter = $_GET['letter'];
// This should load the page showing only the artists with the letters clicked
$rsArtistsmaster = mysql_query("SELECT * FROM artists WHERE lname LIKE '$letter%'")
or die(mysql_error());
?>
Code: Select all
<table border="0" align="center" cellpadding="5"><tr>
<th>Artists</th>
</tr>
<?php do { ?>
<tr>
<td><a href="singersinthenews.php?recordID=<?php echo $row_rsArtistsmaster['id']; ?>"> <?php echo $row_rsArtistsmaster['lname']; ?>, <?php echo $row_rsArtistsmaster['fname']; ?>
<em><?php echo $row_rsArtistsmaster['voice']; ?></em> </a></td>
</tr>
<?php } while ($row_rsArtistsmaster = mysql_fetch_assoc($rsArtistsmaster));
?>
</table>