dousui6488 2012-11-01 20:32 采纳率: 100%
浏览 10
已采纳

复选框,PHP和SQL [关闭]

Quick issue:

I have a checkbox in my code that tells the user if the status of a record is DONE or NOT DONE. When the user does a records search in the database, the records that show up, show up with the current record status (DONE or NOT DONE).

If the checkbox is not check means that the record is NOT DONE, so I'm trying to place a checkbox on one side of the record status so the user can check it as soon as they are done working on the record. After they check the checkbox, the value is sent to the DB telling the DB that the new status of the record is DONE

How can I accomplish this when the following example code: (The results are shown after the user made a search using a form)

<?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>";
    }   
}
?>



Thanks everyone for showing me the way :D
  • 写回答

1条回答 默认 最新

  • douchu5131 2012-11-01 20:41
    关注

    You mean, like this?

    echo "<td class='col7 cell'><input type='checkbox' name='status' ".($record->Status == 'DONE' ? 'checked' : '')."/></td>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂