【发布时间】:2015-11-22 22:21:01
【问题描述】:
我想发出ajax请求来获取数据以对不同的表执行连接操作取决于参数和表名。
$.ajax({ url: '/my/site',
data: {fun_name: 'join_user_and_state',
param: '12,1'
},
type: 'post',
success: function(output) {
alert(output);
}
});
在服务端,读取action POST参数和函数名,对应的值指向要调用的方法,例如:
if(!empty($_POST['param']) && !empty($_POST['fun_name'])) {
$param= $_POST['param']; $fun_name= $_POST['fun_name'];
// want to call proper function name with parametters from $fun_name and $param
// parameters could be 2 or 3 or more its depends upon user choice
// how to call
}
//definitions
join_user_and_state($user_id,$state_id)
{
// will do join query here with 2 tables
}
join_user_and_city($user_id,$city_id)
{
// will do join query here with 2 tables
}
join_user_and_state_and_city($user_id,$state_id,$city_id)
{
// will do join query here with 3 tables
}
如何调用合适的函数?
或者有任何其他方法可以达到相同的效果,我必须执行不同的不同连接查询取决于用户选择,如 user_state、user_city、user_education、user_salary..etc(以及这些的所有组合也是可能的) ?并且这些列存在于它们自己的表中
【问题讨论】:
标签: php mysql function oop parameter-passing