How to loop through the dates? [message #186117] |
Sun, 15 June 2014 16:11 |
Mr Oldies
Messages: 241 Registered: October 2013
Karma:
|
Senior Member |
|
|
http://mroldies.net/radio/tracker2.php
I've got my report generator almost completed.
I only need to know how I can loop through the dates.
In BASIC, this is no big deal.
As a synopsis,
The table "tracker" is consulted for data.
Data is ordered by date.
Data is now transferred to the array $master.
From $master, data is outputted as desired.
In this case, each song played on a given date is listed.
$query = "SELECT * FROM tracker ORDER BY date";
$result = mysqli_query($con, $query);
@$num_results = mysqli_num_rows($result);
/*Loop through each row and display records */
for($i=0; $i<$num_results; $i++) {
$row = mysqli_fetch_assoc($result);
$master[$i]['date']=$row['date'];
$master[$i]['songID']=$row['songID'];
$master[$i]['track']=$row['track'];
$master[$i]['artist']=$row['artist'];
$master[$i]['hits']=$row['hits'];
}
for($i=0;$i<$num_results;$i++){
print $master[$i]['date'];
echo "<br>";
}
echo "<table border=\"1\">";
$newdate=$master[0]['date'];
$ct=0;
print "<tr><td>".$master[$ct]['date']."</td></tr>";
while ($ct<$num_results){
if ($master[$ct]['date']==$newdate) {
print "<tr><td>".$master[$ct]['track']."</td></tr>";
}
$ct++;
}
echo "</table>";
mysqli_close($con);
|
|
|