0) { $limit_sql = " LIMIT $limit"; } foreach ($data as $type=>$value) { /* Create correct Value statement based on method */ $value_string = str_replace("__",$value,$method); switch ($type) { case 'all': /* artist, title, and album, anyway.. */ $value_words = explode(' ', $value); $where_sql .= " ( "; $ii == 0; foreach($value_words as $word) { if($ii++ > 0) $where_sql .= " AND "; $where_sql .= " ( song.title LIKE '%$word%' OR album2.name LIKE '%$word%' OR artist2.name LIKE '%$word%' OR genre2.name LIKE '%$word%' OR song.year LIKE '%$word%' OR song.file LIKE '%$word%' ) "; } $where_sql .= " ) $operator"; $join_sql .= "song.album=album2.id AND song.artist=artist2.id AND song.genre=genre2.id AND "; $table_sql .= "album as album2,artist as artist2, genre as genre2"; break; case 'title': $where_sql .= " song.title $value_string $operator"; break; case 'album': $where_sql .= " album.name $value_string $operator"; $join_sql .= "song.album=album.id AND "; $table_sql .= "album,"; break; case 'artist': $where_sql .= " artist.name $value_string $operator"; $join_sql .= "song.artist=artist.id AND "; $table_sql .= "artist,"; break; case 'genre': $where_sql .= " genre.name $value_string $operator"; $join_qsl .= "song.genre=genre.id AND "; $table_sql .= "genre,"; break; case 'year': $where_sql .= " song.year $value_string $operator"; break; case 'filename': $where_sql .= " song.file $value_string $operator"; break; case 'played': /* This is a 0/1 value so bool it */ $value = make_bool($value); $where_sql .= " song.played = '$value' $operator"; break; case 'minbitrate': $value = intval($value); $where_sql .= " song.bitrate >= '$value' $operator"; break; default: // Notzing! break; } // end switch on type } // foreach data /* Trim off the extra $method's and ,'s then combine the sucka! */ $table_sql = rtrim($table_sql,','); $where_sql = rtrim($where_sql,$operator); $sql = $base_sql . $table_sql . " WHERE " . $join_sql . "(" . $where_sql . ")" . $limit_sql; $db_results = mysql_query($sql, dbh()); while ($r = mysql_fetch_assoc($db_results)) { $results[] = new Song($r['id']); } return $results; } // search_songs /** * show_search * This shows the results of a search, it takes the input from a run_search function call * @package Search * @catagory Display */ function show_search($type,$results) { /* Display based on the type of object we are trying to view */ switch ($type) { case 'artist': break; case 'album': break; case 'genre': break; case 'song': default: show_songs($results); break; } // end type switch } // show_search ?>