
July 10th, 2003, 08:01 PM
|
|
Junior Member
|
|
Join Date: Jul 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Help - PHP/MySQL sending me loopy
I have been trying to get to grips with MySQL/PHP for a couple of weeks now for a fairly basic task and have got a little stuck. I have a table containing song lyrics, the track they're from and the artist performing them, amongst other bits. The following will display a list of artists as links and clicking the link will then display the lyrics...
Quote:
// display individual record
if ($id) {
$result = mysql_query("SELECT * FROM lyrics WHERE lyric_id=$id",$db);
$myrow = mysql_fetch_array($result);
printf($myrow["artist"]);
printf($myrow["track"]);
printf($myrow["lyrics"]);
} else {
// show list
$result = mysql_query("SELECT * FROM lyrics",$db);
if ($myrow = mysql_fetch_array($result)) {
// display list if any to display
do {
printf("<a href=\"%s?id=%s\">%s</a><br>\n", $PHP_SELF, $myrow["lyric_id"], $myrow["artist"]);
} while ($myrow = mysql_fetch_array($result));
} else {
// none to display
echo "Sorry, none found";
}
} |
The thing is, some of the artists have more than one set of lyrics in the database and so they appear twice on the list. What I am trying to do is have another level so that they only appear once on the list, then clicking their name will display a second list of tracks and then clicking the tracks will take you through to the lyrics.
I've tried a few options but keep getting tangled in loops. Is there a simple(ish)way of doing what I want?
Cheers
Rick
|