<input type="checkbox" name="average" value="average" <? if (get_option('average') == 'average'){ echo 'checked="checked"';} ?>>Average
<input type="checkbox" name="petite" value="petite" <? if (get_option('petite') == 'petite'){ echo 'checked="checked"';} ?>>Petite
if ( get_option('average') == 'average' ): // choose category
$average = "AND build = '".get_option('average')."'";
endif;
if ( get_option('petite') == 'petite' ): // choose category
$petite = "OR build = '".get_option('petite')."'";
endif;
$qry = mysql_query("SELECT performerid,pic0 FROM ".$table." WHERE **$average $petite** ORDER BY RAND() LIMIT 20");
How can i make this code work? I need the sql query to work if $average is selected, is both $average and $petite are selected, or just $petite is selected?
TY!
you may use something like this:
$selectedCategories = array();
foreach(array('petite', 'average', 'athletic') as $category)
{
if (get_option($category) == $category)
{
$selectedCategories[] = $category;
}
}
$qry = mysql_query(
"SELECT performerid,pic0
FROM ".$table."
WHERE build IN('" . implode("', '", $selectedCategories) . "')
ORDER BY RAND() LIMIT 20;");
Note: this won't work if you select no category.
you need to use php function isset();
if(isset($_POST)){ //checks if post is set
if(isset($)POST['average']) && !isset($_POST['petite'])){
//do staff only average is set
}
elseif(isset($_POST['petite']) && !isset($_POST['average'])){
//do staff only petite is set
}
elseif(isset($_POST['average'] && isset($_POST['average']))){
//do staff both is set
}
}