The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving details from a Database to table
#1
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)

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>
  Reply


Messages In This Thread
Retrieving details from a Database to table - by sire - 07-05-2017, 05:26 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)