0

快速问题:

我的代码中有一个复选框,告诉用户记录的状态是DONE还是NOT DONE。当用户在数据库中进行记录搜索时,显示的记录会显示当前记录状态(DONENOT DONE)。

如果未选中该复选框,则表示该记录未完成,因此我尝试在记录状态的一侧放置一个复选框,以便用户在完成对记录的处理后立即对其进行检查。在他们选中复选框后,该值被发送到数据库,告诉数据库记录的新状态为DONE

以下示例代码如何完成此操作:(结果显示在用户使用表单进行搜索后)

<?php
if(!isset($_POST['search']))
{
?>

<?php
}
else
{
    $from = trim($_POST['OLD']);
    $to = trim($_POST['NEW']);
    $status = isset($_POST['Status']) ? "AND status = 'DONE' " :"AND status = 'NOT DONE' ";

    $connection = mysql_pconnect("HOST", "USER", "PASS") or die("Connection failed. ".myslq_error());
    mysql_select_db("DBNAME") or die("Unable to select db. ".mysql_error());
    $query = "SELECT * FROM records WHERE Date >= '$from' AND Date <= '$to' ".$status." ORDER BY date ASC";

    $result = mysql_query($query) or die(mysql_error());

    echo "<table class='table' id='SearchResult' cellspacing='0' cellpadding='0'>";
        echo "<tr class='rowa'><b>";
            echo "<td class='col0 cell'>ID</td>";
            echo "<td class='col1 cell'>Name</td>";
            echo "<td class='col2 cell'>Last Name</td>";
            echo "<td class='col3 cell'>Place</td>";
            echo "<td class='col4 cell'>Station</td>";
            echo "<td class='col5 cell'>Phone</td>";
            echo "<td class='col6 cell'>Date of Record</td>";
            echo "<td class='col7 cell'>Status</td>";
        echo "</tr>";
    echo "</table>";
    while($record = mysql_fetch_object($result))
    {   
    echo "<table class='table' id='SearchResult' cellspacing='0' cellpadding='0'>";
        echo "<tr class='rowb'>";
            echo "<td class='col0 cell'>".$record->ID."</td>";
            echo "<td class='col1 cell'>".$record->Name."</td>";
            echo "<td class='col2 cell'>".$record->lastName."</td>";
            echo "<td class='col3 cell'>".$record->Place."</td>";
            echo "<td class='col4 cell'>".$record->Station."</td>";
            echo "<td class='col5 cell'>".$record->Phone."</td>";
            $year_part_of_date = explode('-', $record->date);
            echo "<td class='col6 cell'>".$record->date."</td>";
            echo "<td class='col7 cell'>".$record->Status."</td>";
        echo "</tr>";       
    echo "</table>";
    }   
}
?>



谢谢大家给我指路 :D

4

1 回答 1

0

你的意思是,像这样?

echo "<td class='col7 cell'><input type='checkbox' name='status' ".($record->Status == 'DONE' ? 'checked' : '')."/></td>";
于 2012-11-01T20:41:18.883 回答