A Link That when clicked displays database
Moderator: General Moderators
A Link That when clicked displays database
How would I go about making a menu of A-Z where when I clicked on B it would give a list of the B entries of a certain column DISTINCT.
I've tried to alter my search script but I can't figure out how to change it to instead use a link instead of a form.
I've tried to alter my search script but I can't figure out how to change it to instead use a link instead of a form.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
for a given url of: foo.com/bar.php?letter=A
untested, example
[edit]oops, my bad, missed a single quote...[/edit]
untested, example
Code: Select all
<?php
$letter = preg_match('|^([#a-z])|i', (!empty($_GET['letter'])?$_GET['letter']{0}:'-'), $match);
if(!$letter)
{
echo '[ ';
for($x = 0; $x < 27; $x++)
{
if($x == 0)
$y = '#';
else
$y = chr($x - 1 + ord('A'));
echo '<a href="'.$_SERVER['SCRIPT_NAME'].'?letter='.$y.'">'.$y.'</a> ';
}
echo ']'."\n";
exit;
}
// do your sql connection here
// you'll need to tweak this next line for your particulars
$result = mysql_query("SELECT DISTINCT * FROM `foo` WHERE `bar` LIKE '{$match[1]}%'");
while($row = mysql_fetch_assoc($result))
{
echo '<pre>'.print_r($row,true).'</pre>'; // replace this line with your presentation code
}
?>[edit]oops, my bad, missed a single quote...[/edit]
Last edited by feyd on Thu Jun 24, 2004 6:12 am, edited 1 time in total.
I've altered the script around a bit and its all good apart from the DISTINCT is not working and it is displaying database entries that are the same
Code: Select all
<table><tr><td>Genre</td><td>Artist</td><td>Albums</td><td>Songs</td></tr>
<?php
$letter = preg_match('|^([#a-z])|i', (!empty($_GET['letter'])?$_GET['letter']{0}:'-'), $match);
if(!$letter)
{
echo '[ ';
for($x = 0; $x < 27; $x++)
{
if($x == 0)
$y = '#';
else
$y = chr($x - 1 + ord('A'));
echo '<a href="'.$_SERVER['SCRIPT_NAME'].'?letter='.$y.'">'.$y.'</a> ';
}
echo ']'."\n";
exit;
}
// you'll need to tweak this next line for your particulars
$result = mysql_query("SELECT DISTINCT * FROM songs WHERE artist LIKE '{$match[1]}%'");
while($row = mysql_fetch_array($result))
{
printf("<tr><td>%s</td><td>%s</td><td></td><td></td>\n",
$row[4],$row[2]);}
?>
</table>-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England