我正在尝试在body onload事件中执行一个或两个脚本,该事件从mysql数据库中提取数据,但是当我测试时,第一个if语句是唯一运行的语句。我知道我可能只是构造if语句错误,但无法弄清楚我错过了什么。有问题的两个字段是值为“Y”或“”的复选框:
<body
<?php if($casedetail['field1']==='Y') if($casedetail['field2']==='Y') {echo 'onload= "showCS(); showWC()"';}
else if($casedetail['field1']==='Y') if($casedetail['field2']==='') {echo 'onload= "showCS()"';}
else if($casedetail['field1']==='') if($casedetail['field2']==='Y') {echo 'onload= "showWC()"';} ?> >
答案 0 :(得分:0)
您的语法错误,要使用&&
和运算符
<?php
if(($casedetail['field1']=='Y') && ($casedetail['field2']=='Y')) {
echo 'onload= "showCS(); showWC()"';
}else if(($casedetail['field1']=='Y') && ($casedetail['field2']=='')) {
echo 'onload= "showCS()"';
}else if(($casedetail['field1']=='') && ($casedetail['field2']=='Y')) {
echo 'onload= "showWC()"';
} ?>