Pull All Records from California (CA)
2 |
Lavaysse Circus |
27 Woodland Avenue |
|
San Mateo |
CA |
94402 |
(211) 107-2844 |
21 |
Sherwood Oaks |
1941 aberdeen way |
|
Davis |
CA |
95616 |
(143) 275-2569 |
25 |
Easter Travel |
4114 W. Elm |
Suite 370 |
Stratham |
CA |
03885 |
(330) 871-5564 |
26 |
Richman Buick |
PO BOX 4971 |
|
Boulder |
CA |
80302 |
(131) 664-3716 |
27 |
Daly Autobody |
4388 Folsom Street |
Suite 673 |
Santa Clara |
CA |
95050 |
(642) 915-9286 |
CODE FOLLOWS
<?php
// Enable error reporting for all types of errors
error_reporting(E_ALL);
// Include the header file for page setup
include('includes/header.php');
// Initialize an empty connection variable (though it should be set later)
$con = '';
?>
<h1>Pull All Records from California (CA)</h1>
<!-- Start of table to display client records -->
<table class="full">
<tr>
<!-- Table header with a colspan of 8 for styling purposes -->
<th colspan="8" class="header1">RECORDS</th>
</tr>
<tr class="header2">
<!-- Column headers -->
<th>ID</th>
<th>Name</th>
<th>Address 1</th>
<th>Address 2</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Phone</th>
</tr>
<?php
// Include the database connection file
include('includes/open_db.php');
// Define the SQL query to retrieve records from the clients table where state is 'CA'
$query = "SELECT * FROM clients WHERE state = 'CA'";
// Execute the query; handle errors if the query fails
$result = mysqli_query($con, $query) or die("Could not get data: $query " . mysqli_error($con));
// Loop through each row in the result set and display it in the table
$i = 0;
while ($row = mysqli_fetch_array($result)) {
// Extract data from each row into individual variables
$id = $row['id'];
$name = $row['name'];
$address_1 = $row['address_1'];
$address_2 = $row['address_2'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
?>
<!-- Display each row's data in a table row, with alternating classes for styling -->
<tr class="row<?php echo($i++ & 1); ?>">
<td><?php echo htmlspecialchars($id); ?></td>
<td><?php echo htmlspecialchars($name); ?></td>
<td><?php echo htmlspecialchars($address_1); ?></td>
<td><?php echo htmlspecialchars($address_2); ?></td>
<td><?php echo htmlspecialchars($city); ?></td>
<td><?php echo htmlspecialchars($state); ?></td>
<td><?php echo htmlspecialchars($zip); ?></td>
<td><?php echo htmlspecialchars($phone); ?></td>
</tr>
<?php
}
// Close the database connection
include('includes/close_db.php');
?>
</table>
<hr>
<?php
// Include the footer file to close the HTML structure
include('includes/footer.php');
?>