PDA

View Full Version : lyrics submit


Meltdown
04-13-2004, 02:24 AM
im wantin to create a lyrics site that allows users to submit info from a form and post to a mysql db. the problem is that i want users to be able to sort the lyrics by genres artists etc...any script suggestions or tutorials

dniwebdesign
04-13-2004, 05:08 AM
That is actually easy...

You would first need a table probably with the coloums:

Required
---------
Song
Artist
Lyrics

Optional:
---------
SubmitedBy:
Dates (Cannot use date as it is main keyword)


Then when you add to the form just use your normal insert, and when you display the list just select the rows and order it by a variable sent by the url... example:

http://www.lyrics.com?SortBy=artist

$artist=$_GET["artist"];
$song=$_GET["song"];
$order=$_GET["SortBy"];

$result = mysql_query("SELECT * FROM lyrics ORDER BY ".$order." ASC");
$count=0;
if(mysql_num_rows($result))
{
echo '

<table>
<tr><td>Artist</td><td>Song</td><td>Submited By:</td>
</tr>';


while($row=mysql_fetch_array($result))
{
$count=$count+1;
$artist=$row["artist"];
$song=$row["song"];
$submitted=$row["submitedby"];

if($count <= $front_cols && $count==1){echo "";}
else if($count < $front_cols && $count > 1){echo "";}
else if($count==$front_cols){echo "";}
echo '
<tr><td>$artist</td><td>$song</td><td>$submitted</td>
</tr>';
if($count <= $front_cols && $count==1){echo "<br /><br />\n</td>\n";}
else if($count < $front_cols && $count > 1){echo "<br /><br />\n</td>\n";}
else if($count==$front_cols){echo "<br /><br />\n</td>\n";}
if($count==$front_cols){$count=0;}
}
if($count < $front_cols)
{
$spacer=($front_cols - $count) * 2;
echo "\n<td class=\"bodymd\" colspan=\"$spacer\">&nbsp;&nbsp;</td>\n";
}
echo '</table>
';
}
else
{
echo '<div align="center"><font size="2" face="Arial, Helvetica, sans-serif">We are sorry.
We can\'t seem to find any lyrics.</font></div>
';
}

angst
04-13-2004, 07:35 PM
hey, i'm building a new lyrics site too,
maybe we should work together? ;)

ken@irn.ca

Scrowler
04-16-2004, 04:28 AM
form:

form action=process.php method=post
txtbox name=artist
txtbox name=songname
txtarea name=lyrics

process.php:

$artist = $_POST['artist'];
$songname = $_POST['songname'];
$lyrics = $_POST['lyrics'];

mysql_query("INSERT INTO Lyrics(Artist, SongName, Lyrics) VALUES ('$artist','$songname','$lyrics')") or die("Error inserting lyrics! ".mysql_error());
echo 'If you are seeing this, the lyrics have been entered successfully!';

view.php:

$query = mysql_query("SELECT * FROM Lyrics") or die(mysql_error());
while($row = mysql_fetch_array($query)){
echo '<a href="lyrics.php?id='.$row['id'].'">'.$row['Artist'].' - '.$row['SongName'].'</a><br>';
}

lyrics.php:

if($_GET['id'] == NULL){
die("No song id was selected!");
} else {
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM Lyrics WHERE id = '$id'") or die(mysql_error());
while($row=mysql_fetch_array($query)){

echo 'Artist: '.$row['Artist'];
echo '<br>Song: '.$row['SongName'];
echo '<br>Lyrics: <br><br>';
echo nl2br($row['Lyrics']);

}

that's pretty much all you need for what i think you are doing, hope it helps.