$server = "localhost";
$user = "munsing_karaoke";
$pass = "sp*tlight";
$songquery = $_GET["find"];
$searching = $_GET["searching"];
$sortby = $_GET["sortby"];
$begins = $_GET["letter"];
?>
//Start Letters ?>
#
for ($i = 65; $i <= 90; $i++) {
printf('%1$s ', chr($i));
}
?>
//End Letters ?>
//This is only displayed if they have submitted the form
if ($begins != "") {
//sort by artist, title, or song number - default us artist
$sortby = $_GET["sortby"];
if ($sortby !== "")
{
$sqlExtra = "ORDER BY title ASC, artist ASC";
}
if ($sortby == "artist")
{
$sqlExtra = "ORDER BY artist ASC, title ASC";
}
if ($sortby == "title")
{
$sqlExtra = "ORDER BY title ASC, artist ASC";
}
if ($sortby == "songnumber")
{
$sqlExtra = "ORDER BY songnumber ASC";
}
//If they did not enter a search term we give them an error
if ($begins == "")
{
echo "
oops... something went wrong";
exit;
}
// Otherwise we connect to our Database
mysql_connect("localhost", "munsing_karaoke", $pass) or die(mysql_error());
mysql_select_db("munsing_songbooks") or die(mysql_error());
// We preform a bit of filtering
if ($begins == "num") {
$sql = "SELECT * FROM karaoke WHERE title REGEXP '^[0-9]'" .$sqlExtra;
}
if ($begins !== "num") {
$sql = "SELECT * FROM karaoke WHERE title LIKE '$begins%'" . $sqlExtra;
}
//Now we search for our search term, in the field the user specified
$data = mysql_query($sql);
//And we display the results
//This is only displayed if they have submitted the form
if ($begins !== "") {
echo "
";
}
while(($result = mysql_fetch_array( $data )) !== false)
{
$i++;
$artist = $result['artist'];
$artist = strtoupper($artist);
$artist = strip_tags($artist);
$artist = trim ($artist);
$artist = str_replace("'", "'", $artist);
$title = $result['title'];
$title = strtoupper($title);
$title = strip_tags($title);
$title = trim ($title);
$title = str_replace("'", "'", $title);
$songnumber = $result['songnumber'];
//ECHO ROWS
echo "";
echo "".$artist." | ";
echo "".$title." | ";
echo "".$songnumber." | ";
echo "
\n";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
if ($begins !== ""){
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query
";
}
mysql_close();
}
}
?>