Page 1 of 1
Alphabetical Navigation Bar
Posted: Tue Jan 18, 2005 6:57 am
by Stelios
Hi everybody,
I would like to add to the web site am constructing an aphabetic navigation bar so that users can browse the database according to the song name. What I actually want to do is to redirect a user when they click on, say letter B, a pgae which is going to display all the songs starting with the letter B. Do I need to create a separate database field in my database stating which letter the song begins with or there is a way I can do it by just extracting the first letter of each song from the field that already exists about the song names. I hope I made myself clear and didnt confuse you.
Thanks a lot!
Posted: Tue Jan 18, 2005 7:03 am
by ckuipers
In your select statement do something like
'WHERE title= 'a%'
and you'll get every title that starts with an a
Posted: Tue Jan 18, 2005 7:14 am
by Stelios
Tried to do what you say by performing a direct query to my database in the form:
Code: Select all
select song_name from uploads where song_name='f%';
and although there is a song on my database starting with f I get an empty set back as a return of my query....
Posted: Tue Jan 18, 2005 7:17 am
by ckuipers
Try
WHERE song_name LIKE 'f%'
Posted: Tue Jan 18, 2005 7:21 am
by Stelios
found the correct statement...it should be
WHERE title LIKE '%b%';
Posted: Tue Jan 18, 2005 7:23 am
by ckuipers
if you do '%f%' you get all songs containing and f.
%f will give you ending with an f
f% starting with an f
Posted: Tue Jan 18, 2005 8:24 am
by Stelios
Ok, what Ive done is I have created a small script to display all the alphabet letters which is:
Code: Select all
<?php
echo 'This is a test';
echo '<br>';
for ($i = 'A'; $i != 'AA'; $i++) {
echo '<a href="test_t.php?i='.$i.'">ї'.$i.']</a>';
}
?>
and then another one to display the database entries which is
Code: Select all
<?php
require_once('mysql_connect.php');
$query = "SELECT * FROM uploads WHERE song_name LIKE '$i%' ";
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))
{
echo "<a href={$rowї'song_name']}>" . ($rowї'song_name']) . "</a>";
}
?>
The script is running but is returning me all the entries of the database. Any idea why?

Posted: Tue Jan 18, 2005 8:31 am
by feyd
$i doesn't exist in your script. print the query..
and using the url variable straight is dangerous.
Posted: Tue Jan 18, 2005 8:39 am
by Stelios
what do you mean it doesnt exist? It does in the previous script...Whats wrong?
Posted: Tue Jan 18, 2005 8:40 am
by ckuipers
You have to transfer the data in between your scripts. Knowing a variable in one script doesn't mean you know it in another.
Posted: Tue Jan 18, 2005 8:41 am
by feyd
you're assuming register_globals is on, when it likely isn't. Echo out the query.
also.. set error_reporting to E_ALL.
Posted: Tue Jan 18, 2005 8:42 am
by Stelios
nevermind, I found it, missing a $_GET variable...thanks anyway...