如果未使用sql语句在其中定义示例中的条件,我如何从列名中选择所有记录。
示例:
function getData($condition){
if($condition ==null){
$condition = '*';
}
sql = "select * from table where name=$condition"
}
这只是一个例子,但'*'在select中不起作用。有什么帮助吗?
答案 0 :(得分:1)
试一试:
function getData($condition){
if($condition ==null){
$condition = '1';
}else{
$condition = "`name`={$condition}";
}
sql = "select * from table where $condition";
}
答案 1 :(得分:0)
试试这个
function getData($condition){
if($condition ==null){
$condition = '1=1';
}
else
{
$condition = 'Name='+$condition;
}
sql = "select * from table where $condition"
}