0

我正在尝试检查一个复选框,如果数据库中该字段的值为 1。

我有:

<?php 

$selectedSPK=$_POST['SPKSelect'];
$assigned = $_POST['Sales_Exec'];
$date = $_POST['DateSelect'];

if ($selectedSPK) {
    $Priorityquery = "SELECT  Priority FROM Data WHERE SPKCustNo  = '$selectedSPK' ";
    $Priorityresult = mysql_query($Priorityquery);
    $row = mysql_fetch_array($Priorityresult);
    $checked = $Priorityresult['Priority'];
}
?>
<input name="PriorityCheckBox" type="checkbox" value="1" 
<?php if ($checked == 1) echo ' checked'; ?> />

但没有得到任何快乐,有什么想法吗?

4

6 回答 6

1

试试这个:

您没有使用查询返回的行...

<?php 
    $selectedSPK=$_POST['SPKSelect'];
    $assigned = $_POST['Sales_Exec'];
    $date = $_POST['DateSelect'];
    if ($selectedSPK)
    {
        $Priorityquery = "SELECT  Priority FROM Data WHERE SPKCustNo  = '$selectedSPK' ";
        $Priorityresult = mysql_query($Priorityquery);
        $row = mysql_fetch_array($Priorityresult);
        //$checked = $Priorityresult['Priority']; // <------ this is where you went wrong...
        $checked = $row['Priority']; // <------ this will fix where u went wrong!
    }
    ?>
    <input name="PriorityCheckBox" type="checkbox" value="1" <?php if ($checked == 1){echo ' checked'; }?>
于 2012-10-03T11:48:49.067 回答
1

你应该使用

<?php if ($checked == 1){echo "checked='checked'"; }

并且

$checked = $Priorityresult['Priority']; 

 $checked = $row['Priority'];
于 2012-10-03T11:51:10.830 回答
1

我认为你有一个错误......试试这个

<input name="PriorityCheckBox" type="checkbox" value="1" <?php if ($row['Priority'] == 1) echo ' checked'; ?> />
于 2012-10-03T11:52:46.197 回答
0

试试这个方法

<input name="PriorityCheckBox" type="checkbox" value="1" <?php if ($checked == 1) echo "checked='checked'"; ?> />
于 2012-10-03T11:48:03.883 回答
0

改变

<?php if ($checked == 1) echo ' checked'; ?>

<?php if ($checked == 1) echo ' checked="checked"'; ?>

$checked = $Priorityresult['Priority'];_$checked = $row['Priority'];

于 2012-10-03T11:48:10.247 回答
0

它应该是checked="checked"

<?php if ($checked == 1) echo "checked='checked'"; ?>
于 2012-10-03T11:49:29.857 回答