View Single Post
Old 01-15-2013, 09:34 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
By the by, you could write the condition stuff much simpler:
Code:
$condition = " WHERE validate = 1 AND slng = " $slng ; // assuming slng is a number
if(isset($cat_id) && $cat_id != 0) 
{
    $condition .= " AND category_id=" . $cat_id ;
}
$SQL = "select * from $database_table_name2 " . $condition . " ORDER BY rand() LIMIT 10";
Though you should be sanitizing that $cat_id to make sure it really is a number, to protect against SQL injection.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote