0

This is my code...

<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>

I want to display all of my records in a table, however, it only displays just 1 record of each column.

Here is the rest:

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

?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
josh
  • 1
  • 1
  • where is the rest of your code? like what you're querying for and how you're looping. Your question is unclear. – Funk Forty Niner Nov 30 '18 at 02:34
  • Ah yes, I forgot to include. How do I edit my question. I'm new here and still learning – josh Nov 30 '18 at 02:40
  • https://stackoverflow.com/posts/53550387/edit < click that or the link that says "edit" under your question. – Funk Forty Niner Nov 30 '18 at 02:41
  • Gotcha, I posted it. – josh Nov 30 '18 at 02:44
  • Great. Ok well here's the deal. What you'll need to do is to place your table code inside the loop instead and that gets a bit tricky but not impossible. Here's a link you can have a look at https://stackoverflow.com/q/17902483/1415724 and you can do this yourself. It won't take you long, believe me. Just take your time, study the code in that page and apply it to yours, while working with a copy of your original so you don't overwrite your original. – Funk Forty Niner Nov 30 '18 at 02:48
  • On an added note. Stack lets you post your own answer, given that it works. They also encourage it and I'd be glad to upvote it, that's your choice. You can either do it yourself or wait for someone who will do it for you. The disadvantage to this would be that you'd of not have learned how to do it yourself. When you learn, you remember ;-) I hope you choose the former. – Funk Forty Niner Nov 30 '18 at 02:51
  • I got it now sir, thank you so much! – josh Nov 30 '18 at 03:10

1 Answers1

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

?>

To display the results: replace first block of code in the question with the following code:

<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>
oreopot
  • 3,392
  • 2
  • 19
  • 28