-3

I am trying to put my SQL data into an HTML data, this is the code I have so far but it does not work yet. I have tried to put HTML into my PHP code I am wondering whether I should do it the the other way round(put PHP into HTML), any reply greatly appreciated

  while ($rowObj = $queryResult->fetch_object()) {
echo "<tr>";
echo"<td>" . $AE_events ['eventTitle'] . "</td>;
echo"<td>" . $AE_events ['eventDescription'] . "</td>;
echo"<td;>" . $AE_events ['eventStartDate'] . "</td>;
echo"<td>" . $AE_events ['eventEndDate'] . "</td>;
echo"<td>" . $AE_events ['eventPrice'] . "</td>;

    $AE_eventTitle = $rowObj->eventTitle;
    $AE_eventDescription = $rowObj->eventDescription;
    $AE_eventStartDate = $rowObj->eventStartDate;
    $AE_eventEndDate = $rowObj->eventEndDate;
    $AE_eventPrice = $rowObj->eventPrice;
    echo "<div>  $AE_eventTitle<br> $AE_eventDescription<br>   
$AE_eventStartDate<br> 
$AE_eventEndDate<br> $AE_eventPrice<br> </div>";

}

1 Answers1

0

If you want to draw a table out of data in PHP, you can have to use nested loops. The first loop manages the rows and the nested one manages the columns. Example :

$data = [
    [1, 3, 5],
    [2, 4, 6]
];
print "<table>";
for ($i = 0; $i < count($data); $i++) {
    $row = $data[$i];
    print "<tr>";
    for ($k = 0; $k < count($row); $k++) {
        print "<td>{$row[$k]}</td>";
    }
    print "</tr>";
}
print "</table>";

Outputs:

<table>
    <tr>
        <td>1</td>
        <td>3</td>
        <td>5</td>
    </tr>
    <tr>
        <td>2</td>
        <td>4</td>
        <td>6</td>
    </tr>
</table>
Youmy001
  • 515
  • 3
  • 11