如何显示表中的所有记录?

jxct1oxe  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(369)

这是我的密码。。。

<fieldset>

<legend id="leg"> DAILY RECORD </legend>

    <table cellpadding="12" border="5">
        <tr>

            <td width="7%"> <p id="allrnd"> Record Date:<br><br> <?php echo "<p> $recdate </p>"?> </p> </td>
            <td width="8%"> <p id="allrnd"> Activity No.:<br><br><?php echo "<p> $actno </p>" ?> </p> </td>
            <td width="6%"> <p id="allrnd"> Bldg No.:<br><br><?php echo "<p>$bldgno </p>" ?> </p> </td>
            <td width="6%"> <p id="allrnd"> Floor No.:<br><br><?php echo "<p> $flrno </p>" ?> </p> </td>
            <td width="6%"> <p id="allrnd"> Unit No.:<br><br><?php echo "<p> $unino </p" ?> </p> </td>
            <td width="10%"> <p id="allrnd"> Type:<br><br><?php echo "<p> $type </p>" ?> </p> </td>
            <td width="10.5%"> <p id="allrnd"> Specifics:<br><br> <?php echo "<p> $specs </p> " ?> </p> </td>
            <td width="10%"> <p id="allrnd"> Materials Outgoing:<br><br><?php echo "<p> $mout </p>" ?> </p> </td>
            <td width="10%"> <p id="allrnd"> Materials Incoming:<br><br><?php echo "<p> $min </p>" ?> </p> </td>
            <td width="13%"> <p id="allrnd"> Requested By / Delivered By:<br><br><?php echo "<p> $rqstd </p>" ?> </p> </td>
            <td width="8%"> <p id="allrnd"> Remarks / Name:<br><br><?php echo "<p> $rem </p>" ?> </p> </td>
            <td width="5%"> <p id="allrnd"> DR No.:<br><br><?php echo "<p> $drno </p>" ?> </p> </td>
        </tr>           

    </table>

    <br>
    <br>

</fieldset>

我想在一个表中显示我的所有记录,但是,它只显示每列的一条记录。
剩下的是:

<?php

    $con = mysqli_connect("localhost", "root", "", "inventory");

    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 

    $sql = "SELECT recdate, actno, bldgno, flrno, unino, type, specs, mout, min , rqstd, drno, rem FROM scaffoldingrecs";
    $result = $con->query($sql);

    if ($result->num_rows >  0) {

    while($row = $result->fetch_assoc()) {

        $recdate = $row["recdate"];
        $actno = $row["actno"];
        $bldgno= $row["bldgno"];
        $flrno = $row["flrno"];
        $unino = $row["unino"];
        $type = $row["type"];
        $specs = $row["specs"];
        $mout = $row["mout"];
        $min = $row["min"];
        $rqstd = $row["rqstd"];
        $drno = $row["drno"];
        $rem = $row["rem"];

    }
        } else {
            echo "0 results";
    }

?>
7gyucuyw

7gyucuyw1#

<?php

    $con = mysqli_connect("localhost", "root", "", "inventory");

    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 

    $sql = "SELECT recdate, actno, bldgno, flrno, unino, type, specs, mout, min , rqstd, drno, rem FROM scaffoldingrecs";
    $result = $con->query($sql);

    if ($result->num_rows >  0) {
    $dataArr = [];
    while($row = $result->fetch_assoc()) {
        $temp=[];

        $temp['recdate'] = $row["recdate"];
        $temp['actno']   = $row["actno"];
        $temp['bldgno']  = $row["bldgno"];
        $temp['flrno']   = $row["flrno"];
        $temp['unino']   = $row["unino"];
        $temp['type']    = $row["type"];
        $temp['specs']   = $row["specs"];
        $temp['mout']    = $row["mout"];
        $temp['min']     = $row["min"];
        $temp['rqstd']   = $row["rqstd"];
        $temp['drno']    = $row["drno"];
        $temp['rem']     = $row["rem"];

        $dataArr[] = $temp;//adding current set of results

    }
        } else {
            echo "0 results";
    }

?>

显示结果:用以下代码替换问题中的第一个代码块:

<fieldset>

<legend id="leg"> DAILY RECORD </legend>

    <table cellpadding="12" border="5">
        <?php if(isset($dataArr) && count($dataArr)){ 
        foreach($dataArr as $key => $row){

        $recdate = $row["recdate"];
        $actno = $row["actno"];
        $bldgno= $row["bldgno"];
        $flrno = $row["flrno"];
        $unino = $row["unino"];
        $type = $row["type"];
        $specs = $row["specs"];
        $mout = $row["mout"];
        $min = $row["min"];
        $rqstd = $row["rqstd"];
        $drno = $row["drno"];
        $rem = $row["rem"];

        ?>
        <tr>
            <td width="7%"> <p id="allrnd"> Record Date:<br><br> <?php echo "<p> $recdate </p>"?> </p> </td>
            <td width="8%"> <p id="allrnd"> Activity No.:<br><br><?php echo "<p> $actno </p>" ?> </p> </td>
            <td width="6%"> <p id="allrnd"> Bldg No.:<br><br><?php echo "<p>$bldgno </p>" ?> </p> </td>
            <td width="6%"> <p id="allrnd"> Floor No.:<br><br><?php echo "<p> $flrno </p>" ?> </p> </td>
            <td width="6%"> <p id="allrnd"> Unit No.:<br><br><?php echo "<p> $unino </p" ?> </p> </td>
            <td width="10%"> <p id="allrnd"> Type:<br><br><?php echo "<p> $type </p>" ?> </p> </td>
            <td width="10.5%"> <p id="allrnd"> Specifics:<br><br> <?php echo "<p> $specs </p> " ?> </p> </td>
            <td width="10%"> <p id="allrnd"> Materials Outgoing:<br><br><?php echo "<p> $mout </p>" ?> </p> </td>
            <td width="10%"> <p id="allrnd"> Materials Incoming:<br><br><?php echo "<p> $min </p>" ?> </p> </td>
            <td width="13%"> <p id="allrnd"> Requested By / Delivered By:<br><br><?php echo "<p> $rqstd </p>" ?> </p> </td>
            <td width="8%"> <p id="allrnd"> Remarks / Name:<br><br><?php echo "<p> $rem </p>" ?> </p> </td>
            <td width="5%"> <p id="allrnd"> DR No.:<br><br><?php echo "<p> $drno </p>" ?> </p> </td>
        </tr>           
        <?php } else { ?>    
        <tr> No data found. </tr>
        <?php } ?>
    </table>

    <br>
    <br>

</fieldset>

相关问题