$category = get_option('category');
// checks to see if subcategory is enabled in the option page
if ( get_option('enable_subcategory') == 'y' ):
$subcategory = get_option('subcategory');
endif;
$qry = mysql_query("SELECT car,number FROM ".$table."
WHERE category = '$category' AND subcategory = '$subcategory'
ORDER BY RAND() LIMIT 20");
如果未启用子类别选项,我如何编写$ query以便“ AND子类别='$ subcategory'”消失?
最佳答案
添加了$subSql
var:
<?
$category = get_option('category');
if ( get_option('enable_subcategory') == 'y' ): // checks to see if subcategory is enabled in the option page
$subcategory = get_option('subcategory');
$subSql = "AND subcategory = '$subcategory'";
endif;
$qry = mysql_query("SELECT car,number FROM ".$table." WHERE category = '$category' $subSql ORDER BY RAND() LIMIT 20");
?>