我试图减少在我的代码中的选择语句,更新等的数量,所以我认为我会尝试为此创建一个函数,但是我很困惑我的努力在第一个障碍中失败。
我已经非常全面地搜索了这个问题(我感觉),而且我找不到我所找到的例子有任何不同之处。
这是我的功能与打印语句完成,以帮助我诊断问题。
function select_statement($action, $table, $where){
print $action.' - ';
switch ($action){
case 'select':
print 'select used - ';
$thequery = 'SELECT * FROM '. $table . ' WHERE '. $where;
case 'insert':
print 'insert used - ';
$thequery = 'INSERT INTO '. $table;
case 'update':
print 'update used - ';
$thequery = 'UPDATE ' . $table . ' SET ';
}
print $thequery;
mysql_query($thequery);
}这是调用该函数的行: -
$logins = select_statement('select', 'users', 'user_id=1');//calls function这是结果: -
select - select used - insert used - update used - UPDATE users SET正如您所看到的,代码正在触发每个打印语句,并且似乎忽略了'case'语句。
我真的不确定我在这里做错了什么?