Re: Aligning HTML table columns in PHP
I had another look at your code.
You need to open the <table> before looping through the records returned.
The code you have will make a one row table of each row, and I don't think that's what you mean.
Something like this
<html>
<head>
<style>
#traffic {
width:500px;
}
td {
width: 15%;
}
.la{
text-align:left;
}
</style>
</head>
<body>
<table id="traffic">
<?php
// build SQL. Nominate fields required.
$sql = "SELECT
address
, city
, state
, zipcode
, longitude
, latitude
FROM log
ORDER BY zipcode
LIMIT 100";
// fetch log records from database
$row = mysqli_query($dbconnect,$sql); //assuming you get $dbconnect elsewhere
// Loop Through Dataset
while ($fields = mysqli_fetch_array($row))
{
$address = $fields['address'];
$city = $fields['city'];
$state = $fields['state'];
$zipcode = $fields['zipcode'];
$longitude = $fields['longitude'];
$latitude = $fields['latitude'];
?>
<!-- Present Table -->
<tr>
<td class="la"><?php echo $address; ?></td>
<td class="la"><?php echo $city; ?></td>
<td class="la"><?php echo $state; ?></td>
<td class="la"><?php echo $zipcode; ?></td>
<td class="la"><?php echo $longitude; ?></td>
<td class="la"><?php echo $latitude; ?></td>
</tr>
<?php
// End While Loop
$countah = $countah + 1;
}
?>
<!-- End Table -->
</table>
<br />
<?php
echo "Total Unique IP Addresses (Limit = 100): " . $countah . "<br>";
?>
</body>
</html>
Good luck,
Barry.
Subject
Written By
Posted
Re: Aligning HTML table columns in PHP
January 19, 2022 03:10PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.