Revision: 8836
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 10, 2008 07:45 by conspirator
Initial Code
<?php
// Establish database connection
$db_host = 'localhost';
$db_name = 'DB NAME';
$db_user = 'YOUR USER NAME';
$db_pass = 'YOUR PASSWORD';
$db_table = 'DB TABLE';
// Connect to database
$link = mysql_connect($db_host, $db_user, $db_pass);
$db = mysql_select_db($db_name);
// Generate SELECT query
$sql = "SELECT date_saved, atm, access, loan, checking, online, advantage, contact_name, contact_email, contact_zip FROM quiz_responses ORDER BY date_saved DESC";
$result = mysql_query($sql, $link);
// Loop through the results/rows
if ($result) {
echo "<table id='quiz_responses' cellspacing='0' cellpadding='3' border='0'>n"; // Open a table
echo "<thead>n<tr>n";
echo "<th>Date Saved</th>";
echo "<th>Contact Name</th>";
echo "<th>Contact Email</th>";
echo "<th>Contact Zip</th>";
echo "<th>ATM Response</th>";
echo "<th>Access Response</th>";
echo "<th>Loan Response</th>";
echo "<th>Checking Response</th>";
echo "<th>Online Response</th>";
echo "<th>Advantage Response</th>";
echo "</tr>n</thead>n<tbody>";
while($row = mysql_fetch_array($result)) { // Pull each row from the table
echo "<tr>n";
echo "<td>" . $row['date_saved'] . "</td>";
echo "<td>" . $row['contact_name'] . "</td>";
echo "<td>" . $row['contact_email'] . "</td>";
echo "<td>" . $row['contact_zip'] . "</td>";
echo "<td>" . $row['atm'] . "</td>";
echo "<td>" . $row['atm'] . "</td>";
echo "<td>" . $row['access'] . "</td>";
echo "<td>" . $row['loan'] . "</td>";
echo "<td>" . $row['checking'] . "</td>";
echo "<td>" . $row['online'] . "</td>";
echo "<td>" . $row['advantage'] . "</td>";
echo "</tr>n";
}
echo "</tbody>n</table>"; // Close the table
} else {
echo "No records were found. Perhaps the database is empty?";
}
?>
Initial URL
Initial Description
Initial Title
Get DB data using PHP
Initial Tags
php, textmate
Initial Language
Other