And if you're ever in need of more exercize then here is the rest of my tri-laffathon.
/////////////////////////////////////////
This is the code for the section of the Listening Room that echoes tables full of song and band info. You can reach this page directly or searching for songs on the search page will process and display results here. It seems like way too much redundant info. As I wrote up the code hints tonight I realized that there are two distinnct sections for whether processing results from the sort page or from accessing the page directly. Would i be better off using the search processing as an include?
CUT IN HALF TO FIT POST LIMIT
$genre=$_GET['genre'];
////function to shorten lengthy genre names
function abbrevGenre($input) {
if($input=="Experimental"){
$input=="Experimntl";
}
elseif($input=="Electronic"){
$input=="Electrnc";
}
elseif($input=="Soundtrack"){
$input=="Soundtrk";
}
elseif($input=="Native American"){
$input=="Natv Amercn";
}
return $input;
}
//pagination items
$limit = 5;
$page = $_GET['page'];
if(!$page)
{
$page = 1;
}
///Typically $genre variable vould be an actual musical genre such as "Reggae".
//If member has arrived to page by performing a query on search page then $genre will be "search"
if($genre==search){
//search by keyword
if (isset($_POST['keysearchbtn'])) {
$st = "key"; //set search type to key
$srch = $_POST['keysearch']; //inputted keyword
}
//search by rating
elseif (isset($_POST['ratesearch'])) {
$st = "rate"; //set search type to rate
$sty = $_POST['ratingbtn']; //will be either "high" or "low" for sorting songs by best or worst score
$sg = $_POST['srchgenrerate']; //genre to perform search in
}
//search by date
elseif (isset($_POST['datesearch'])) {
$st = "date"; //set search type to rate
$sty = $_POST['dat']; //either "new" or "old" for sorting songs by latest or oldest
$sg = $_POST['srchdate']; //genre to perform search in
}
//if variables not set via posts then must be in URL
else{
$st = $_GET['st'];
$srch = $_GET['srch'];
$sty = $_GET['sty'];
$sg = $_GET['sg'];
}
///////////keyword search////////
if($st == "key"){
//tally songs for pagination
$query_count = "SELECT COUNT(*) FROM songs WHERE stitle LIKE '%$srch%'";
$result_count = mysql_query($query_count, $conn);
$totalrows = mysql_result($result_count, 0);
$limitvalue = $page * $limit - ($limit);
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs WHERE stitle LIKE '%$srch%' ORDER BY sdate DESC, stime DESC LIMIT $limitvalue, $limit";
}
/////////rating search//////////
elseif($st == "rate"){
if($sg == "ag"){ //if genre is "any genre"
$query_count = "SELECT COUNT(*) FROM songs WHERE beat != 1";
}
else{ //if genre is specific
$query_count = "SELECT COUNT(*) FROM songs WHERE sgenre = '$sg'";
}
$result_count = mysql_query($query_count, $conn);
$totalrows = mysql_result($result_count, 0);
$limitvalue = $page * $limit - ($limit);
if($sg == "ag"){
if($sty==high){ //if sorting by highest scores
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs ORDER BY score DESC LIMIT $limitvalue, $limit";
}
elseif($sty==low){ //if sorting by lowest scores
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs ORDER BY score ASC LIMIT $limitvalue, $limit";
}
}
else{ //if genre is specific
if($sty==high){
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs WHERE sgenre = '$sg' ORDER BY score DESC LIMIT $limitvalue, $limit";
}
elseif($sty==low){
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs WHERE sgenre = '$sg' ORDER BY score ASC LIMIT $limitvalue, $limit";
}
}
}
/////////date search//////////
elseif($st == "date"){
if($sg == "ag"){ //if genre is "any genre"
$query_count = "SELECT COUNT(*) FROM songs";
}
else{ //if genre is specific
$query_count = "SELECT COUNT(*) FROM songs WHERE sgenre = '$sg'";
}
$result_count = mysql_query($query_count, $conn);
$totalrows = mysql_result($result_count, 0);
$limitvalue = $page * $limit - ($limit);
if($sg == "ag"){
if($sty==newa){ //if sorting by newest songs
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs ORDER BY sdate DESC, stime DESC LIMIT $limitvalue, $limit";
}
elseif($sty==old){ //if sorting by oldest songs
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs ORDER BY sdate ASC, stime ASC LIMIT $limitvalue, $limit";
}
}
else{
if($sty==newa){
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs WHERE sgenre = '$sg' OR sgenre2 = '$sg' ORDER BY sdate DESC, stime DESC LIMIT $limitvalue, $limit";
}
elseif($sty==old){
$getInfo = "SELECT songid, mp, bandid, stitle, bandName, DATE_FORMAT(sdate, '%c/%e/%Y') AS sngdate, DATE_FORMAT(sdate, '%l:%i %p') AS stime, sgenre, sgenre2 FROM songs WHERE sgenre = '$sg' OR sgenre2 = '$sg' ORDER BY sdate ASC, stime ASC LIMIT $limitvalue, $limit";
}
}
}
}