Php 在发布页面之前,如何获取所选下拉列表的值
(结果是没有错误和插入。我做错了什么?类似于:Php 在发布页面之前,如何获取所选下拉列表的值,php,jquery,codeigniter,Php,Jquery,Codeigniter,(结果是没有错误和插入。我做错了什么?类似于: $db_num = $this->input->post('db_num'); $units = $this->input->post('units'); $answer = $db_num * $units; ... echo $answer; 函数functionwhereyouwilldothemath(el){//el=javascript表单对象 var db_num=;//是的,这是合法的。 //做你
$db_num = $this->input->post('db_num');
$units = $this->input->post('units');
$answer = $db_num * $units;
...
echo $answer;
函数functionwhereyouwilldothemath(el){//el=javascript表单对象
var db_num=;//是的,这是合法的。
//做你的数学题
return true;//将导致页面在提交时重新加载。
}
传递我的变量的数据库字段需要设置为INT
-问题已解决。使用php内爆函数存储和分解函数显示
$itm=$_POST[‘医院科’];
$comma_separated=内爆(“-”,$itm)
你为什么不在你的控制器里乘法呢?我就是这么做的。。不工作。您知道如何临时禁用codeigniter中页面的禁止直接访问吗?我不熟悉codeigniter,因此如果此答案错误,请原谅我,但您可能需要将结果转换为int:
$answer=(int)$db_num*(int)$units代码>你说它不工作是什么意思?如果您尝试在控制器中设置var_dump$db_num
和$units
,会发生什么情况?如果你有一个单独的问题(看起来完全无关),请把它作为一个单独的问题,不要在评论中提问。
$db_num = $this->input->post('db_num');
$units = $this->input->post('units');
$answer = $db_num * $units;
...
echo $answer;
<form ... onsubmit="return functionwhereyouwilldothemath(this)" >
</form>
<script type="text/javascript">
function functionwhereyouwilldothemath(el) { //el = javascript form object
var db_num = <?=$db_num?>; //yup this is legit.
//do your math
return true; //will cause the page to reload uppon submit.
}
</script>
$data['hospital_department'] = $comma_separated;