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

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.