I am adding a database to my event website with the webpages mon-sun each with its own SQL table. Each page can have any number of events. The table has 6 columns (ID,name,club,location,host,description). Currently I am using a tiresome method to call the data. I'm looking for an addition to my code so that calling the data is a bit more automated. My code so far.
<?php
$dbhost = 'localhost';
$dbname = 'events';
$dbuser = 'max';
$dbpass = '';
$appname = "Dundaah";
$connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($connection->connect_error) die($connection->connect_error);
function queryMysql($query)
{
global $connection;
$result = $connection->query($query);
if (!$result) die($connection->error);
return $result;
}
$row = queryMysql("SELECT * FROM monday WHERE ID=1");
$one = $row->fetch_array(MYSQLI_ASSOC);
$row2 = queryMysql("SELECT * FROM monday WHERE ID=2");
$two = $row2->fetch_array(MYSQLI_ASSOC);
?>
Then to call for the first event I use.
<?php echo ucwords(strtolower($one['name']));?>
<?php echo ucwords(strtolower($one['club']));?>
<?php echo ucwords(strtolower($one['location']));?>
<?php echo ucwords(strtolower($one['host']));?>
<?php echo ucwords(strtolower($one['description']));?>
For the second event I use the same method but I'm looking for a way to loop through instead of declaring a new fetch array every time. Thank you.
</div>