如何在php中的每一行之前创建复选框?

时间:2013-07-30 23:52:46

标签: php html mysql session

任何人都可以告诉我如何在每行显示来自mysql的数据时创建复选框。如果我检索10行,则复选框的数量必须为10,这样我可以选择其中一行进行进一步操作

<?php

    $query = "select p.usn, p.name, p.sem, p.year, cg.cur_cgpa, c.cc1, c.cc2, c.cc3, c.cc4, c.cc5, 
                    c.cc6, c.cc7, c.cc8, c.cc9 from personal_details p, course_codes c, cgpa_details cg 
              where p.usn = c.usn AND p.usn = cg.usn order by p.usn";

    $run = mysql_query($query) or die($query."<br/><br/>".mysql_error()); 
    $num = mysql_numrows($run);
    // echo "No. of registered students: $num";
    echo $num;
    while($row = mysql_fetch_assoc($run)){
        echo "<tr>";
        echo "<td ><a href = info.php?id=" . ">" . $row['usn'] . "</a>" . "</td>";

        echo "<td>" . $row['name'] . " </td>";
        echo "<td>" . $row['sem'] . " </td>";
        echo "<td>" . $row['year'] . " </td>";
        echo "<td>" . $row['cur_cgpa'] . " </td>";
        echo "<td>" . $row['cc1'] . " </td>";
        echo "<td>" . $row['cc2'] . " </td>";
        echo "<td>" . $row['cc3'] . " </td>";
        echo "<td>" . $row['cc4'] . " </td>";
        echo "<td>" . $row['cc5'] . " </td>";
        echo "<td>" . $row['cc6'] . " </td>";
        echo "<td>" . $row['cc7'] . " </td>";
        echo "<td>" . $row['cc8'] . " </td>";
        echo "<td>" . $row['cc9'] . " </td>";

        if(isset($_GET['submit'])){
            $_SESSION['session_usn'] = $_GET['usn'];
        }
    }
    echo "</tr>";

1 个答案:

答案 0 :(得分:1)

在表格中添加新内容并在其中放置一个复选框。

 while($row = mysql_fetch_assoc($run)){
    echo "<tr>";
    echo '<td><input type="checkbox" name="ticked[]" value="' . $row['usn'] . '"></td>';

然后继续使用原始代码。