1. Osclass Forum
  2. Other
  3. Trying to get expire_date from table in model plugin sms_pay...

Trying to get expire_date from table in model plugin sms_payements

Started by smos, September 18, 2021, 4:52 pm

  • 1

smos

I am trying to get a date from db with model in plugin

For now i have in model:

Code: [Select]
​  public function getExpire( $today ) {
    $this->dao->select();
    $this->dao->from( $this->getTable_PremiumExpire() );
    $this->dao->where('date(expire_date) = "' . $today . '"');

    $result = $this->dao->get();

    if( !$result ) { return array(); }
    $prepare = $result->result();
    return $prepare;
  }

In user_item where i want to echo the expire_date there is 

Code: [Select]
​<?php
$today = ModelSP::newInstance()->getExpire( 'expire_date') ;
?>
<?php echo date('d/m/Y', strtotime('expire_date')); ?>

But it keeps on showing 01/01/1970 instead of the date that is in db.....

I am new with this so all help would be very much appreciated....


calinbehtuk

I don't really understand what you want to get but the code is wrong.


Code: [Select]
$this->dao->where('date(expire_date) = "' . $today . '"');


That is not a correct syntax.


This also is not a correct syntax.

Code: [Select]
​<?php echo date('d/m/Y', strtotime('expire_date')); ?>


I don't know the plugin and i don't understand what you want to get from database. You want to get items by date, or single item?
What is the content of that table?


smos

I want to echo the premium expire date from table oc_t_item_sms_premium_expire as attached and echo the date in user_items.php

For now there is:

Expire date: 10/09/2021

Publish date: 02/08/2021

I want to add:

Premium end on:   expire_date but that doesn't seem to work after days of trying unfortunately

Hope you can point me out.....

Attached is the table oc_t_item_sms_premium_expire


 


smos

I want to echo the premium expire date from table oc_t_item_sms_premium_expire as attached and echo the date in user_items.php per item.

For now there is:

Expire date: 10/09/2021

Publish date: 02/08/2021

I want to add:

Premium end on:   expire_date but that doesn't seem to work after days of trying unfortunately

Hope you can point me out.....

Attached is the table oc_t_item_sms_premium_expire



calinbehtuk

You can use this function, just added in you theme functions.php file. Make sure that is before the closing php tag ?>.


This function will return the date from that field based on item id.


Code: [Select]
​function item_sms_premium_expire_date($item_id = null) {

    /*
    * You can pass the item_id when you use this function if the item id is not exported
    * in most cases the item id is exported so we use the below check
    */
   
    $item_id = ($item_id < 1 ) ? ((osc_premium_id() > 0) ? osc_premium_id() : ((osc_item_id() > 0) ? osc_item_id() : null)) : $item_id;

    $dao = new DAO();
    $table = 't_item_sms_premium_expire';
    $dao->dao->select('*');
    $dao->dao->where('item_id', $item_id);
    $dao->dao->from(DB_TABLE_PREFIX . $table);
    $result = $dao->dao->get();
    if (!$result->row()) {
        return NULL;
    }
    $date = $result->row();

    return $date['expire_date'];
}


And you add the line in the area that you want to display you date


Code: [Select]
​<?php echo item_sms_premium_expire_date(); ?>



  • << Last edit: September 19, 2021, 1:54 pm by calinbehtuk >>
  • Quote

smos

Wow ;-) Great work! Thank you very much. It works perfectly now...

Looks so easy but i was trying almost 4 full days to get it it work. Learning is hard :-)

Now last question about this:

Date shows also on items that are not in oc_t_item_sms_premium_expire ...In user_items.php i am trying to put 

Code: [Select]
<?php if(osc_has_premiums() <> '') { ?>


but that gives the error: Notice: Undefined index: premiums in /home/u441*7***/domains/w***.be/public_html/test/oc-includes/osclass/core/View.php on line 89
Any idea how to show only output to items that are in table ?

  • << Last edit: September 19, 2021, 3:26 pm by smos >>
  • Quote

smos

Solved in meantime sorry:


  <?php if (osc_item_is_premium()) {  ?>

  • 1
Subscribe
X

Subscribe!

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