I'm in the process of rewriting a web site from ColdFusion to PHP. I've run into some trouble trying to match and increment dates.
I have a table called 'TourShows' which hold data about live shows for a band. The fields include the ShowID, Venue, Location, Day. The day field is what I'm concerned about.
The code as it currently is shown works, however, the query runs in a continuous loop. It appears the date is not being incremented by 1 day like I want. Basically, I'm finding what today's date is, then quering the database to see if today's date matches with a show. If it doesn't, then I increment today by 1 day, then run the query again to find a match, this is done until a match is found, then the output is displayed. The code is shown below:
<?php
// Create new date for today
$todaycount = date('Y-m-j');
// Set counter
$x = 1;
// Run query until the dates match
require('../db_info.php');
while($x = 1) {
$query = "SELECT ShowID, Location, Venue, date_format(Day, '%Y-%m-%e') AS f_day1
FROM TourShows
WHERE Day = $todaycount";
$result = mysql_query($query) or die ('Error executing query: <br>'. mysql_error());
// If query returns nothing, increment $todaycount by 1 day
if(!$result) {
$todaycount = date('Y-m-j', strtotime('+1 Day'));
}
// If query does return a result, set $x to 0
else {
$x = 0;
}
}
// Display results of query
while($row = mysql_fetch_array($result)) {
// Assign table variables
$location = $row['Location'];
$venue = $row['Venue'];
$day = $row['f_day1'];
echo "<div align=\"left\"><span class=\"redbgtext\"><strong>location:/strong> $location<br><br>
<strong>venue:</strong> $venue<br><br><strong>date:</strong>
$day</span></div>";
}
mysql_close($connection);
?>
Any help would be greatly appreciated.