crazyfrog Posted February 17, 2007 Share Posted February 17, 2007 Hi, Can anyone see a problem with this bit of code? <?php session_start(); foreach ($_SESSION['_amember_subscriptions'] as $sub); //This is line 53 if ($sub['payment_id']){ $diff = (strtotime($s['expire_date']) - time()) / (3600*24); if ($diff > 0){ print "Your subscription expires in $diff days"; print ("$sub"); } } ?> I am getting the following error and cant understand why. reading through other topics, i seem to think it is something to do with arrays? Warning: Invalid argument supplied for foreach() in /home/*****/public_html/tester.php on line 53 Thanks Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 <?php session_start(); $x=$_SESSION['_amember_subscriptions']; foreach($x as $sub){ if ($sub['payment_id']){ $diff = (strtotime($s['expire_date']) - time()) / (3600*24); if ($diff > 0){ print "Your subscription expires in $diff days"; print ("$sub"); } } } ?> Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 Still getting the same error That was a damn fast reply though! Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 foreach ($_SESSION['_amember_subscriptions'] as $sub); //This is line 53 Warning: Invalid argument supplied for foreach() in /home/*****/public_html/tester.php on line 53 this is caused when $_SESSION['_amember_subscriptions'] is not an array. You may want to double check this. Also, giving a line like foreach ($_SESSION['_amember_subscriptions'] as $sub); // this is meaningless because you terminated the foreach loop with the semicolon ';' before it can actually do anything: foreach ($_SESSION['_amember_subscriptions'] as $sub) { // your code here } Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 this is caused when $_SESSION['_amember_subscriptions'] is not an array. You may want to double check this. How would i find out? Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 var_dump(is_array($_SESSION['_amember_subscriptions'])); if you have bool (true), it is an array, false mean it is not. Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 Damn, its not! Any remedies? Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 if it is not an array, there is no point to use foreach loop isn't it? Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks for all your help, but i am new to php and am finding it quite interesting. would i just remove foreach from the code then? Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 Your code expect $sub to be an array as well. So, I am sure if you remove the foreach, it still won't work. Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 Ah well. Really needed this to work. Thankyou very much for all your help. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 How are you setting the session value? Ken Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 How are you setting the session value? Ken I dont quite understand? I am trying to add a line of text to my site something like "Your subscription will end in ** days" Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 You want to use "$_SESSION['_amember_subscriptions']". How/where are you putting something into this session variable? Ken Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 It is created in mysql when the user subscribes for a selected period. Hope this is what you mean Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 Please post the code that sets the value. Ken Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 I think i will leave it, i can see this getting too technical for a N0ob. :'( I wouldnt know where to look. Thankyou Quote Link to comment Share on other sites More sharing options...
crazyfrog Posted February 17, 2007 Author Share Posted February 17, 2007 Please post the code that sets the value. Ken Would this be something like the signup.php page source? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.