Page 1 of 1
A Link That when clicked displays database
Posted: Thu Jun 24, 2004 2:38 am
by jeggah
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.
Posted: Thu Jun 24, 2004 2:56 am
by feyd
for a given url of: foo.com/bar.php?letter=A
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]
Posted: Thu Jun 24, 2004 5:02 am
by jeggah
im getting this error
Parse error: parse error, unexpected '[', expecting ']'
Posted: Thu Jun 24, 2004 6:01 am
by patrikG
Post the code with the line containing the error highlighted.
Posted: Thu Jun 24, 2004 6:12 am
by feyd
try it now..
Posted: Thu Jun 24, 2004 9:17 am
by jeggah
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>
Posted: Thu Jun 24, 2004 9:28 am
by patrikG
Posted: Sat Jun 26, 2004 6:42 pm
by jeggah
is it me or is the text on that website loads of little squares???
Posted: Sat Jun 26, 2004 10:41 pm
by d3ad1ysp0rk
I see the ones in the title..
Posted: Sun Jun 27, 2004 12:02 am
by feyd
it's in japanese..
Posted: Sun Jun 27, 2004 6:10 am
by jeggah
oh noes
i cant read japanese
Posted: Sun Jun 27, 2004 12:19 pm
by jeggah
can someone help me then with my problem about DISTINCT
Posted: Sun Jun 27, 2004 12:32 pm
by kettle_drum
What is the problem? feyd's script told you what to do.
Posted: Mon Jun 28, 2004 7:33 am
by jeggah
there is a problem with feyds script, it doesnt show DISTINCT but all of them
Posted: Mon Jun 28, 2004 7:37 am
by patrikG
read up in the mysql manual on distinct or google for it. Feyd showed you pretty much all there is to it.