Table cells flushed white
Upon running the below SQL statement (which works perfectly) I've found that all tables in my database are flushed white.
Any idea as to why this happening?
// check database for necessary updates
$update = mysql_query("SELECT * FROM rent WHERE colour='3C0'");
while($row_update = mysql_fetch_array( $update )) {
$datetime_lower = DateTime::createFromFormat('d/m/Y', $min);
$datetime_upper = DateTime::createFromFormat('d/m/Y', $max);
$datetime_compare = DateTime::createFromFormat('d/m/Y g:i a', $row_update['pDate']);
if ($datetime_lower < $datetime_compare && $datetime_upper > $datetime_compare) {
// date is between do nothing
mysql_close($update);
开发者_高级运维 } else {
// date is not between so update
echo "date is not between";
$update_result = mysql_query("UPDATE rent SET colour='F0F0F0' WHERE substr(pDate, 0, 10) NOT BETWEEN $min AND $max && colour='3C0'");
mysql_close($update_result);
}
}
I've included a few pictures.
This is how it is meant to look like (above code omitted):
http://i51.tinypic.com/143gpef.jpg
This is how it currently looks like (above code present):
http://i54.tinypic.com/2lwm4xg.jpg
Your while
loop appears to go through all the results from your table. It appears that on each iteration of the loop, you check the date first in PHP, then you check the date again in your update query, and update all matching rows to F0F0F0.
I don't know why your code is changing the colour to white instead of #F0F0F0, since there is no white or fff in your code, so all I can do is suggest something to make your code more efficient.
Instead of updating all rows on each iteration of the while loop, if you have an id
column (Primary Key with Auto-increment) in your rent
table, you can use this value in your while loop instead of having to test the date a second time.
$update = mysql_query("SELECT * FROM rent WHERE colour='3C0'");
while($row_update = mysql_fetch_array( $update )) {
$datetime_lower = DateTime::createFromFormat('d/m/Y', $min);
$datetime_upper = DateTime::createFromFormat('d/m/Y', $max);
$datetime_compare = DateTime::createFromFormat('d/m/Y g:i a', $row_update['pDate']);
if ($datetime_lower < $datetime_compare && $datetime_upper > $datetime_compare) {
// date is between do nothing
mysql_close($update);
} else {
// date is not between so update
echo "date is not between";
$update_result = mysql_query("UPDATE rent SET colour='F0F0F0' WHERE id=" . $row_update['id'] . " && colour='3C0'");
mysql_close($update_result);
}
}
精彩评论