I built a basic application that is pulling data from an outside source and storing it in the database.
My next step is retrieving this information and using it in the HTML output for the dashboard. The code I came up with is below, and it is the most basic query and variable system I can think of, yet when I put it into my test environment, it doesn’t work. I would consider myself relatively new to php in this application, but from all the research I have done, this seems to be the best route. Any help or suggestions would be appreciated.
I have tried several different styles for making a sql connection, and even tried storing the variables globally, but had no luck. Also, I have put this code through several formatters to ensure everything is correct, as well as going over by hand after to try and make sure it didn’t add something it shouldn’t have.
<?php
$servername = "localhost";
$username = "root";
$password = "******";
$dbname = "wallboard";
// Retreave Morning Record Data
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT date, team, dollar_amount, car_count FROM morning";
if ($result = mysqli_query($conn, $sql)) {
// output data into variables
$dateb = $result["date"];
$teamb = $result["team"];
$damountb = $result["dollar_ammount"];
$ccountb = $result["car_count"];
}
else {
echo "Error Retreaving Data/No Data Found in morning table";
}
$conn->close();
// Retreave Lunch Record Data
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT date, team, dollar_amount, car_count FROM lunch";
if ($result = mysqli_query($conn, $sql)) {
// output data into variables
$datel = $result["date"];
$teaml = $result["team"];
$damountl = $result["dollar_ammount"];
$ccountl = $result["car_count"];
}
else {
echo "Error Retreaving Data/No Data Found in lunch table";
}
$conn->close();
// Retreave Lunch Record Data
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT date, team, dollar_amount, car_count FROM dinner";
if ($result = mysqli_query($conn, $sql)) {
// output data into variables
$dated = $result["date"];
$teamd = $result["team"];
$damountd = $result["dollar_ammount"];
$ccountd = $result["car_count"];
}
else {
echo "Error Retreaving Data/No Data Found in dinner table";
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<div>
<div>
<h1>Drive Thru Records</h1>
</div>
<div>
<h2>Breakfast Record</h2>
<h3>Team</h3>
<p><?php
echo $teamb;
?></p>
<h3>Dollar Amount</h3>
<p><?php
echo $damountb;
?></p>
<h3>Car Count</h3>
<p><?php
echo $ccountb;
?></p>
<h3>Date</h3>
<p><?php
echo $dateb;
?></p>
</div>
<div>
<h2>Lunch Record</h2>
<h3>Team</h3>
<p><?php
echo $teaml;
?></p>
<h3>Dollar Amount</h3>
<p><?php
echo $damountl;
?></p>
<h3>Car Count</h3>
<p><?php
echo $ccountl;
?></p>
<h3>Date</h3>
<p><?php
echo $datel;
?></p>
</div>
<div>
<h2>Dinner Record</h2>
<h3>Team</h3>
<p><?php
echo $teamd;
?></p>
<h3>Dollar Amount</h3>
<p>?php echo $damountd; ?></p>
<h3>Car Count</h3>
<p><?php
echo $ccountd;
?></p>
<h3>Date</h3>
<p><?php
echo $dated;
?></p>
</div>
</div>
</head></html>
Expected result would be that the program pulls the data from the database, assign it to the variables, and then uses echo to place in the correct spot in the HTML.
At this point when I run the code in my test environment, all I get is a page of the code, and no logs or anything to help on screen, I’m stuck, please help!