$nestedData[] = '<select id=verify_('.$row['user_id'].')onchange="verifystatus(this.value)" style="width:80px;">
<option value="reason.php?status=1&user='.$row['user_id'];if($status=='1'){ echo 'selected'; }'>Active</option>
<option value="reason.php?status=2&user='.$row['user_id'];if($row['status']=='2'){ echo 'selected'; } '\'>Suspend</option>
<option value="reason.php?status=3&user='. $row['user_id'];if($row['status']=='3'){ echo 'selected'; } '\'>Terminate</option>
</select>';
我在这段代码中有点混淆,它会引用单引号和双引号。
我可以请求澄清
答案 0 :(得分:0)
您的选项标签的值已打开(双)引号,但您尝试使用单引号关闭它们。基本上HTML总是有双引号。您尝试关闭的引号也可能在header("charset: UTF-8; Content-type: text/css")
之后结束。此外,活动选项的状态变量与其他选项(selected
)不同。另一个问题是,你将其余部分放在一个变量中,然后回应“选中”。
如果变量$row['status']
确实存在,这将是您能获得的最佳输出:
$status
所以要解决这个问题,首先需要将echo替换为字符串连接。然后我们需要检查HTML的双引号,然后你可能会得到所需的结果:
selected<select id=verify_(1)onchange="verifystatus(this.value)" style="width:80px;">
<option value="reason.php?status=1&user=1
哪个会输出:
$nestedData[] = '<select id="verify_('.$row['user_id'].')" onchange="verifystatus(this.value)" style="width:80px;">
<option value="reason.php?status=1&user=' .$row['user_id'] . '"' . ($row['status'] == '1' ? ' selected' : '') . '>Active</option>
<option value="reason.php?status=2&user=' . $row['user_id'] . '"' . ($row['status'] == '2' ? ' selected' : '') . '>Suspend</option>
<option value="reason.php?status=3&user=' . $row['user_id'] . '"' . ($row['status'] == '3' ? ' selected' : '') . '>Terminate</option>
</select>';
答案 1 :(得分:0)
<?php
$var = "<select id='verify_".$row['user_id']." onchange='verifystatus(this.value)' style='width:80px;'>";
$var .= "<option value=reason.php?status=1&user=".$row['user_id'].">Active</option>";
$var .= "<option value='reason.php?status=2&user=".$row['user_id'].">Suspend</option>";
$var .= "<option value='reason.php?status=3&user=".$row['user_id'].">Terminate</option>";
$var .= "</select>";
//echo $var ;
?>
答案 2 :(得分:0)
你非常接近。在大多数情况下,你只需要单引号和双引号,然后进行一些小的调整。例如,你不能在你试图用变量定义变量的字符串中做一个if语句。您需要将if语句的结果连接到变量的末尾。
$nestedData[];
$string = "<select id=verify_(" .$row["user_id"] . ")onchange='verifystatus(this.value);' style='width:80px;'> <option value=reason.php?status=1&user=" . $row["user_id"];
$string .= ( $row["status"] == "1" ? " selected=selected" : "" );
$string .= " >Active</option> <option value=reason.php?status=2&user=" .$row["user_id"];
$string .= ( $row["status"] == "2" ? " selected=selected" : "" );
$string .= " >Suspend</option> <option value=reason.php?status=3&user=" . $row["user_id"];
$string .= ( $row["status"] == "3" ? " selected=selected" : "" );
$string .= " >Terminate</option> </select>";
$nestedData[] = $string;