option to redirect if renewal coming up?

12 years 2 months ago - 12 years 2 months ago #191657 by ThePiston
Replied by ThePiston on topic Re: option to redirect if renewal coming up?

krileon wrote: You'll want to retrieve both values, strtotime them, then do your comparison. If you're using $_CB_framework->now() however it's time() so you don't need to strtotime it.

when I try to strtotime the result of querying the expiry_date of logged in user, I get this error:

strtotime() expects parameter 1 to be string.

$query = "SELECT expiry_date
  from jos_cbsubs_subscriptions
  where user_id=$user->id and status='A'";

$result = mysql_query($query);

$exp_date=strtotime($result);

Isn't the date in expiry_date a string?

CB 2.3, CBsubs 4.3, PHP 7.1, J! 3.9.X

Please Log in to join the conversation.

12 years 2 months ago - 12 years 2 months ago #191812 by krileon
Replied by krileon on topic Re: option to redirect if renewal coming up?
That's because you're not using MYSQL properly. You never returned the results. mysql_query just sends the query for execution. You need to retrieve the results with mysql_result.
$query = "SELECT expiry_date
  from jos_cbsubs_subscriptions
  where user_id=$user->id and status='A'";
 
$result		=	mysql_result( mysql_query( $query ) );
 
$exp_date	=	strtotime( $result );

If is inside of Joomla then I recommend using CB or at the least Joomla API to perform your query; direct PHP MYSQL functions won't be necessary. Example as follows with Joomla API.
$db	=	JFactory::getDbo();
$query	=	$db->getQuery( true );

$query->select( 'expiry_date' );
$query->from( '#__cbsubs_subscription' );
$query->where( "user_id = '" . (int) $user->id . "' AND status = 'A'" );

$db->setQuery( $query );

$result	=	$db->loadResult();


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.202 seconds

Facebook Twitter LinkedIn