0

I have a HTML table and the data is from the database. I've then added a second table.

The table is shown by clicking the row. The row is expanded and shows the second table.

What is wrong with my code? It gives data from database but it doesn't loop. For example, I'm expecting 3 rows, but it only output one row.

The query is correct.

This is the code for the second table,

<table class="table">
    <thead>
    <tr>
        <th>Name</th>
        <th>Date filled</th>
        <th>Date signed</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <?php 


    require_once 'dbconfig.php';
    try {

    $conn = new PDO("mysql:host=$host;dbname=$dbname",
        $username, $password);

    $_tempp1 = $row1['tracknum'];
    $stmt = $conn->prepare("CALL sp_gettransactsignatory(?)");
        $stmt->bindParam(1, $_tempp1, PDO::PARAM_STR, 30);
        $stmt->execute();


        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>

    <tr>
        <td><?php echo $row['signatoryname'] ?></td>
        <td><?php echo $row['datefilled'] ?></td>
        <td><?php echo $row['datesigned'] ?></td>

    </tr>


    <?php
    }



    } catch (PDOException $pe) {
    die("Error occurred:" . $pe->getMessage());
    }

    ?>
    </tr>

    </tbody>
</table>

</td>
</tr>
2
  • 4
    Why <tr> before <?php ? Commented Mar 3, 2016 at 16:24
  • remove <tr> before <?php and </tr> before </tbody>. Also some ; are missed too. that's may not a big deal Commented Mar 3, 2016 at 16:33

1 Answer 1

3

Changes are commented :-

  <tr>
        <td colspan="5">

            <table class="table">
            <thead>
              <tr>
                <th>Name</th>
                <th>Date filled</th>
                <th>Date signed</th>
              </tr>
            </thead>
            <tbody>
              <!-- remove <tr> -->
            <?php 
            require_once 'dbconfig.php';
            try {   
                $conn = new PDO("mysql:host=$host;dbname=$dbname",
                $username, $password);

                $_tempp1 = $row1['tracknum'];
                $stmt = $conn->prepare("CALL sp_gettransactsignatory(?)");
                $stmt->bindParam(1, $_tempp1, PDO::PARAM_STR, 30); 
                $stmt->execute();
                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
                  <tr>
                    <td><?php echo $row['signatoryname']; ?></td><!-- ; missed -->
                    <td><?php echo $row['datefilled']; ?></td><!-- ; missed -->
                    <td><?php echo $row['datesigned']; ?></td><!-- ; missed -->
                 </tr>
            <?php}} catch (PDOException $pe) {
                die("Error occurred:" . $pe->getMessage());
            }?> 
            <!-- remove </tr> -->
            </tbody>
            </table>
        </td>
    </tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.