-1

I'm using Drupal 7, my requirement is to automatically update the node field value in a content type for a condition. I have used Hook_menu() for to get a link and if i use that link my code will execute(In Cron). Below is my code,

hook_menu():

function status_url_menu() {
$items = array();
$items['update_status'] = array(
'title' => 'Status Update',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'update_status_url',
);

return $items;
}

And to fetch db table data i used db_query()(I have few additional codes too but this is my core concept for my condition):

  function update_status_url(){
   $results2 = db_query('SELECT * FROM {field_data_field_status_tracker}');
   foreach($results2 AS $result2){
   $entity_id2 = $result2->entity_id;
   $in = 'Inactive';
   if($entity_id2==568){
        if($mydate2<$nowDate){  // Comparing current system date with my field
          db_query("UPDATE {field_data_field_status_tracker} SET field_status_tracker_value = $in WHERE entity_id = $entity_id2");

   }
  }
 }
}

I'm getting error in db_query(update.. line

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Inactive' in 'field list'

And I also tried like this too:

$result2->my_field = $in;

No use i can't update my db field value, whether I'm using wrong method to update field value or please help me to rectify my problem. Thanks in advance... :)

| improve this question | | | | |
1

I changed the code like this and it worked.

db_query("UPDATE {field_data_field_status_tracker} SET field_status_tracker_value = 'Inactive' WHERE entity_id = $entity_id2");

Thanks :)

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.