Reputation: 2790
I am trying to execute a mysql query in joomla where it takes a variable in where clause with the first item in drop-down is please select. I can set the value of drop-down to any value.
myquery is like this:
$db = JFactory::getDbo();
$m = $db->getQuery(true);
$m="SELECT group_concat(distinct m.email
SEPARATOR ', ' ) FROM member m, email e
where m.club_name='{email___club_email}' ";
$db->setQuery($m);
$a = $db->loadresult();
var_dump($a);exit;
return $a;
Now How I should put a clause in this query so that If I select "please select" then the where clause in the statement is ignored or I can get all the records in any other manner in the resultset.
Upvotes: 1
Views: 763
Reputation: 2488
You could set the value of the "please select" option as 0, and then do a simple if:
$m="SELECT group_concat(distinct m.email SEPARATOR ', ' ) FROM member m, email e";
if ($email) {
$m .= " where m.club_name='{email___club_email}' ";
}
Upvotes: 1
Reputation: 827
You can use something which is always true, like WHERE 1 = 1
, which will return all records.
Upvotes: 1
Reputation: 1557
Try something like where m.club_name LIKE '{email___club_email}'"
and change the value
of "please select" to %
as the %
is a wildcard in MySQL
Upvotes: 1