07-05-2017, 05:26 AM
im trying to Retrieve details from customers Database and display a simple table
i spent a few weeks on trying to make it work with the standards for userspice
(thus im asking help)
i spent a few weeks on trying to make it work with the standards for userspice
(thus im asking help)
Code:
<?php
Code:
$user = 'admin';
Code:
$pass = '1admin';
Code:
$db = new PDO( 'mysql:host=localhost;dbname=my_database', $user, $pass );
Code:
$sql = "SELECT * FROM customers";
Code:
$query = $db->prepare( $sql );
Code:
$query->execute();
Code:
$results = $query->fetchAll( PDO::FETCH_ASSOC );
Code:
?>
Code:
<table class="table">
Code:
<tr>
Code:
<th>ID</th>
Code:
<th>First Name</th>
Code:
<th>Surname</th>
Code:
<th>Address</th>
Code:
<th>Email</th>
Code:
</tr>
Code:
<?php foreach( $results as $row ){
Code:
echo "<tr><td>";
Code:
echo $row['id'];
Code:
echo "</td><td>";
Code:
echo $row['first_name'];
Code:
echo "</td><td>";
Code:
echo $row['surname'];
Code:
echo "</td><td>";
Code:
echo $row['address'];
Code:
echo "</td><td>";
Code:
echo $row['email'];
Code:
echo "</td>";
Code:
echo "</tr>";
Code:
}
Code:
?>
Code:
</table>