1. Osclass Forum
  2. Other
  3. I need help on a function in one off my plugins to update a ...

I need help on a function in one off my plugins to update a table in model

Started by smos, September 28, 2021, 3:44 pm

  • 1

smos

I am using a plugin so users can sms there items to top off the search list. When payment is successful table item gets updated with publish date only. 

I want on same transaction to also update column dt_expire with 30 days later.

original is: 


Code: [Select]
  public function moveTopByItemId( $item_id ) {
    $aSet = array('dt_pub_date' => date('Y-m-d H:i:s'));
    $aWhere = array('pk_i_id' => $item_id);

    return $this->_update($this->getTable_Item(), $aSet, $aWhere);
  }


What i need is to also have in same array to add 30 days on dt_expiration but i don't know how to put this in the same arrow... need help....

Something like this but then correctly coded :-)

Code: [Select]

  public function moveTopByItemId( $item_id ) {
    $aSet = array('dt_pub_date' => date('Y-m-d H:i:s'));

    $aSet = array('dt_expiraration' => date('Y-m-d H:i:s')); +30 days
    $aWhere = array('pk_i_id' => $item_id);

    return $this->_update($this->getTable_Item(), $aSet, $aWhere);
  }

Hope this can be achieved...thank you....

calinbehtuk

Set the new date like this:


Code: [Select]
​date('Y:m:d H:i:s', strtotime('+30 days'));


So:


Code: [Select]
​$aSet = array('dt_expiraration' => date('Y:m:d H:i:s', strtotime('+30 days')));


smos

@calinbehtuk


Thank you but that is only to update 1 column and i need it top update 2 columns in same row at the same time. 1-dt_pub_date = today and 2-dt_expiration = today+30 days


I also gave you the wrong dt_expiraration :-) typo mistake


I tried: 

Code: [Select]
​  public function moveTopByItemId( $item_id ) {
    $aSet = array(
      'dt_pub_date' => date('Y-m-d H:i:s'),
      'dt_expiration' => date('Y:m:d H:i:s', strtotime('+30 days')
);
    $aWhere = array('pk_i_id' => $item_id);
    return $this->_update($this->getTable_Item(), $aSet, $aWhere);
  }

But that gives errors....

smos

Found it ... I forgot some )

Solved with:

Code: [Select]
  public function moveTopByItemId( $item_id ) {
    $aSet = array(
      'dt_pub_date' => date('Y-m-d H:i:s'),
      'dt_expiration' => date('Y:m:d H:i:s', strtotime('+30 days')));
    $aWhere = array('pk_i_id' => $item_id);
    return $this->_update($this->getTable_Item(), $aSet, $aWhere);
  }

Thanks for your help (again)


  • 1
Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.