douhuai4155 2016-07-08 08:58
浏览 32
已采纳

使用带有HTML和PHP的Checkbox(SQLite数据库)

I am trying to set the value of my checkbox. I do have a SQLite database with a table with some rows. Some rows contain STATUS = 1, some contain STATUS = 0.

... "STATUS" BOOL NOT NULL DEFAULT 1, ...

So I check the current row with the fetchArray function and everything else works fine, but in my HTML site, all checkboxes are checked. Is there a logical mistake?

while ($row = $table->fetchArray(SQLITE3_ASSOC))
{
    $output .= '<tr>';

    if ($row['STATUS'] == 1) {
        $output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS" checked="true"></td>';
    }
    else {
        $output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS" checked="false"></td>';
    }

    $output .= '<td class="USER" data-id2="' . $row['ID'] . '" contenteditable="true">' . $row['USER'] . '</td>
                ...
                <td class="DESCRIPTION" data-id11="' . $row['ID'] . '" contenteditable="true">' . $row['DESCRIPTION'] . '</td>
                <td><button type="button" name="btn_edit" data-id12="' . $row['ID'] . '" class="btn btn-xs btn-warning btn-block btn_edit">Edit</button></td>
                <td><button type="button" name="btn_delete" data-id13="' . $row['ID'] . '" class="btn btn-xs btn-danger btn-block btn_delete">Delete</button></td>
            </tr>';
}
  • 写回答

1条回答 默认 最新

  • dongyong3554 2016-07-08 10:54
    关注

    This is the solution:

    if ($row['STATUS'] == 1) {
        $output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS" checked>' . $row['STATUS'] . '</td>';
    }
    else {
        $output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS">' . $row['STATUS'] . '</td>';
    }
    

    As you can see, I just changed the syntax of the HTML code. I don't know why the checked property has to be used like this, but to be honest I don't really care. ;-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀