-1

I am trying to echo my database results into a bootstrap 4 card, each row result will be in its own bootstrap card.

I have been able to show the results in a table

Echo to table - THIS WORKS

<table class="table table-striped">

  <?php echo "<table class='table table-striped mb-none'>";

// table header
echo "<tr><th>Company Name</th><th>Date Requested</th><th>Request By</th><th>Graphic Type</th><th>Double Sided</th><th>Design Info</th><th>Purpose</th><th>Approved</th><th>Approval Date</th></tr>";

// output data of each row
while($row=mysqli_fetch_assoc($designresult)) {

    echo "<tr><td>".$row["companyName"]."</td><td>".$row["dateReq"]."</td><td>".$row["yourName"]."</td><td>".$row["graphicType"]."</td><td>".$row["doubleS"]."</td><td>".$row["info"]."</td><td>".$row["purpose"]."</td><td>".$row["approved"]."</td><td>".$row["appDate"]."</td></tr>";
}

// table footer

echo "</table>";

?>

My attempt at echoing into cards

<?php 
// output data of each row
while($row=mysqli_fetch_assoc($designresult)) {

echo "
<div class="card mb-4 box-shadow"> div class="card-header">
            <h4 class="my-0 font-weight-normal">Track Design</h4>
          </div>
          <div class="card-body">
            <p> Company Name ".$row["companyName"]."; </p>
          </div>
        </div>";

}
?>

1 Answers1

0

In the first solution you are escaping " in using ' quotes.

In the second one, you are using " in your HTML code. As you echo that and your echo starts with " aswell, you are ending the echo.

echo "<div class=" <-- Ending the echo, not starting the class name 

You have to change it to this:

echo "<div class='card mb-4 box-shadow'>"

You can also close the PHP tag:

<?php 
// output data of each row
while($row=mysqli_fetch_assoc($designresult)) {

?>

<div class="card mb-4 box-shadow"> 
    <div class="card-header">
        <h4 class="my-0 font-weight-normal">Track Design</h4>
    </div>
    <div class="card-body">
        <p> Company Name <?php echo $row["companyName"]; ?> </p>
    </div>
</div>

<?php

}
?>
davidev
  • 7,694
  • 5
  • 21
  • 56