here's the full script.
<html><form name="form" action="test.php" method="get">
<div align="center">
<p>
<input name="q" type="text" value="soulmates!">
by
<select name="field">
<Option VALUE="band">band</option>
<Option VALUE="title">song title</option>
<Option VALUE="lyrics">lyrics</option>
</select>
<input name="Submit" type="submit" class="submit" value="search!">
</p>
</div>
</form></html>
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$search = trim($var);
$trimmed="%".$search."%";
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>you didn't enter anything useful!</p>";
exit;
}
//connect to db
mysql_connect("localhost","user","password"); //(host, username, password)
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("ihear6_songs") or die("Unable to select database"); //select which database we're using
// Build SQL Query
if ( $field == "lyrics" ) {
$query = "SELECT lyrics,
MATCH(lyrics)
AGAINST (\"%$trimmed%\" IN BOOLEAN MODE) AS score FROM songs
WHERE MATCH(lyrics)
AGAINST (\"%$trimmed%\" IN BOOLEAN MODE) ORDER BY score DESC";
} elseif ($field == "band") {
$query = "select * from songs WHERE band LIKE '$trimmed'";
} elseif ($field == "title") {
$query = "select * from songs WHERE title LIKE '$trimmed' || filename LIKE '$trimmed'";
} else {
echo "<p>uh oh! there seems to be a problem, dear.<p>";
}
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// If we have no results...
if ($numrows == 0)
{
echo "<p>sorry, dear! i couldn't find anything matching your search!</p>";
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$result = mysql_query($query) or die("Couldn't execute query");
// display what the person searched for
echo "<p>you searched for: <strong>" . $var . "</strong></p>";
// begin to show results set
$count = 1 + $s ;
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["title"];
$folder = $row["folder"];
$band = $row["band"];
$filename = $row["filename"];
echo "<p><strong>$count) </strong><a class=\"songs\" href=\"http://songs.iheartadelie.org/songs/$link\">$title</a></p>" ;
$count++ ;
}
//break before paging
echo "<br/>";
?>