Please keep in mind I am new and still learning when reading the following.
What I am doing
I have the following code which pulls a sport, tournament and round NR, from a DB table called event
where the event is still active.
The Problem
The code works and does what I want it to do, but my problem is looking at the code makes me sick, I know there are more efficient ways to achieve what I am trying to do but I am unsure of where to start to improve the code below, I would like to move to a more object orientated or at least a more efficient way of coding.
I would appreciate it if one of the more experienced members of the community could give the code a look and provide some pointers.
$date = date('Y-m-d');
//get sport & tournament
$sql = "Select distinct sport, tournament, round FROM event WHERE date > $date AND active = 'y'";
$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
while($row = mysqli_fetch_array($result)){
$sport[] = $row['sport'];
$tournament[] = $row['tournament'];
$round[] = $row['round'];
}
//make form with tournament & sport
?>
<form name="select" name="sport" method="post">
<!--GET SPORT ON SELECT -->
<select name="sport">
<?php
//get sport
foreach($sport as $index => $sportCode){
echo '<option value="'. $sport[$index].'">'.$sport[$index].'</option>';
}
?>
</select>
<!--GET TOURNAMENT ON SELECT -->
<select name="tournament">
<?php
//get tournament
foreach($tournament as $index => $tournamentCode){
echo '<option value="'. $tournament[$index].'">'.$tournament[$index].'</option>';
}
//get round
?>
</select>
<select name="round">
<?php
foreach($round as $index => $roundNr){
echo '<option value="'. $round[$index].'">'.$round[$index].'</option>';
}
//get round
?>
</select>
</form>
Sports Stats
. – pacmaninbw Jul 15 at 15:00