MySQL Update - Am I going mad?
Posted: Mon Oct 10, 2005 1:38 am
I have a load of dates in my database and want to increase them all by one week. When I test the mysql code in phpMyAdmin it works for the single date, but when using the following code it just makes all of the dates the same.
The thing that really confuses me is that the echo actually displays the correct data and what I'm trying to do.
Code: Select all
$miss_date = $_POST['miss_date']; // The first date to miss
$start_date = $_POST['start_date']; // The date to come back on
list($match_year, $match_month, $match_day) = split('[:.-]', $start_date);
$start_date_timestamp = mktime(0,0,0,$match_month,$match_day,$match_year);
?>
<table class="tborder" cellpadding="6" cellspacing="1" border="0" width="100%">
<tr class="thead">
<td align="center" nowrap="nowrap">Information</td>
</tr>
<tr class="tbody">
<td align="center" nowrap="nowrap">
<?
$query = mysql_query("SELECT DISTINCT date FROM $league ORDER by date ASC") or die(mysql_error());
$num=mysql_num_rows($query);
$i=0;
while ($i < $num) {
$sql_date=mysql_result($query,$i,"date");
if($sql_date >= $miss_date) {
$date_from_timestamp = date('Y-m-d',$start_date_timestamp);
echo "Change Date - ".$sql_date." to ".$date_from_timestamp."<br>";
mysql_query("UPDATE $league SET date = '$date_from_timestamp' WHERE date='$sql_date'") or die(mysql_error());
$start_date_timestamp = strtotime('+7 days',$start_date_timestamp);
}
$i++;
}
?>
</td>
</tr>
</table>