I am trying to refactor some code that selects a category from a database and then displays the listing on a website. Basicly it looks like this:
if($_GET['category'] == 'All') {
$results = mysql_query("SELECT * FROM members ORDER BY company ASC");
}
elseif($_GET['category'] == 'Alterations') {
$results = mysql_query('SELECT * FROM members WHERE category1="Alterations" OR category2="Alterations" OR category3="Alterations" OR category4="Alterations" OR category5="Alterations" ORDER BY premium DESC, featured DESC, CASE WHEN featured = 1 THEN RAND() ELSE company END ASC');
}
elseif($_GET['category'] == 'Apparel') {
$results = mysql_query('SELECT * FROM members WHERE category1="Apparel" OR category2="Apparel" OR category3="Apparel" OR category4="Apparel" OR category5="Apparel" ORDER BY premium DESC, featured DESC, CASE WHEN featured = 1 THEN RAND() ELSE company END ASC');
}
elseif($_GET['category'] == 'Bachelor') {
$results = mysql_query('SELECT * FROM members WHERE category1="Bachelor" OR category2="Bachelor" OR category3="Bachelor" OR category4="Bachelor" OR category5="Bachelor" ORDER BY premium DESC, featured DESC, CASE WHEN featured = 1 THEN RAND() ELSE company END ASC');
}
... (there are a ton of categorys)
I am trying to replace the code above (100s of lines) with something like the following:
if(isset($_GET['category'])) {
$category = $_GET['category'];
$results = mysql_query('SELECT * FROM members WHERE category1="{$category}" OR category2="{$category}" OR category3="{$category}" OR category4="{$category}" OR category5="{$category}" ORDER BY premium DESC, featured DESC, CASE WHEN featured = 1 THEN RAND() ELSE company END ASC');
}
else {
$results = TRUE;
}
However when I run the above code nothing gets echoed to the webpage. Can anyone shed some light as to why this might be? (I relize I have not included the code that echos to the page but it runs fine with the first code snipbit I posted).