Jump to content

[SOLVED] what is wrong with this simple code?


engelsol

Recommended Posts

I am trying to update all record with a new date format. But it just take the last record date in the query and fill everything with that same date....please help

 

        $q  = "SELECT * FROM table_stories";
        $result = mysql_query($q);

        while ($row = mysql_fetch_array($result))
        {
        $storyid = $row["story_id"];
        $edition_date = $row["edition_id"];
        $edition_year = substr($edition_date,-4);
        $edition_month = substr($edition_date,0, 2);	
        $edition_day = substr($edition_date,-6, 2);		
$new_edition_fotmat = "$edition_year$edition_month$edition_day";

        $q  = "UPDATE table_stories SET 
               edition_id = '$new_edition_fotmat , 
               created_stamp = '$edition_year-$edition_month-$edition_day' , 
               modified_stamp = '$edition_year-$edition_month-$edition_day' , 
               published_stamp = '$edition_year-$edition_month-$edition_day' ";
               mysql_query($q);
        }

 

 

Thanks in advance

 

Engel

You're missing a where clause from your UPDATE query. Im guessing it was supposed to be:

 

<?php
        $q  = "UPDATE table_stories SET 
               edition_id = '$new_edition_fotmat , 
               created_stamp = '$edition_year-$edition_month-$edition_day' , 
               modified_stamp = '$edition_year-$edition_month-$edition_day' , 
               published_stamp = '$edition_year-$edition_month-$edition_day' WHERE story_id = '$storyid' ";
               mysql_query($q);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.