Trying to get expire_date from table in model plugin sms_payements
on :September 18, 2021, 4:52 pm #518
I am trying to get a date from db with model in plugin
For now i have in model:
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
<?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....
Re: Trying to get expire_date from table in model plugin sms_payements
on :September 18, 2021, 8:06 pm #519
I don't really understand what you want to get but the code is wrong.
$this->dao->where('date(expire_date) = "' . $today . '"');
That is not a correct syntax.
This also is not a correct syntax.
<?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?
Re: Trying to get expire_date from table in model plugin sms_payements
on :September 18, 2021, 8:57 pm #520
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
Re: Trying to get expire_date from table in model plugin sms_payements
on :September 18, 2021, 8:58 pm #521
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
Re: Trying to get expire_date from table in model plugin sms_payements
on :September 19, 2021, 11:28 am #522
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.
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
<?php echo item_sms_premium_expire_date(); ?>
Re: Trying to get expire_date from table in model plugin sms_payements
on :September 19, 2021, 11:56 am #523
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
<?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 ?
Re: Trying to get expire_date from table in model plugin sms_payements
on :September 19, 2021, 3:47 pm #524
Solved in meantime sorry:
<?php if (osc_item_is_premium()) { ?>