LuxCal Forum

The place for questions, suggestions and news about the LuxCal Event Calendar

User:   Password:   Remember Me?   
LuxCal Forum / General / Support / if statements in retrieve.php?
Posted:  28 Feb 2011 13:47
Thanks for the help so far.. I Really appreciate it. I feel like i'm asking lots of things, and i apologize.. but honestly its only after i've tried and tried and tried and tried to get it solved/fixed myself with no luck.

I'm working on conditional calendars based on different ways to call the info from the database. so far i'm using different Retrieve.php files, based on if the $Get varibles for the different possibilities are set.. I was thinking it'd be much easier to instead of having like 10 different retrieve php files, to just be able to put those if statements inside the retrieve.php. as far as i can tell the reading info from the database is all saved inside the $q0 variable. and i've seen something like that used before, but in an ajax script. and it broke the $x = part, added if statements or other coding, and then resumed the X= again to continue.. i'm guessing thats possible here as well.. i just can't get the syntax down.. but basically i want to be able to add conditional if statements to include "AND" lines to further define what is pulled up.. so stuff like..

so like:

        d.status >= 0
    //process non-recurring events
    $q1 = $q0."

if ($_SESSION['State']) { $q0 = "AND e.venue_state = '".$_SESSION['State']."'"; }

        AND d.r_type = 0
        AND ((d.s_date <= '$end') AND (IF(d.e_date != '9999-00-00', d.e_date, d.s_date) >= '$start') )

would be ideal so then i could add all the different if statements needed right where they need to go. instead of having a different file, for each possible senario

as a side note, i'm not sure why, but Session variables are the only variable i've been able to get to move onto the retrieve.php file. if i set a variable like $StateID = $Get['State'];  in month.php then retrieve.php won't recognize that variable which I thought was weird, but perhap s i'm just having a hard time getting it to parse that way correctly, i'm not sure.

but other ways to organize it, i'll be adding is like by band, venue, City, State, Own Events, etc.

thanks man..
Posted:  28 Feb 2011 23:03   Last Edited By: Roel B.
OK, first relax . . . :) I assume you are using LuxCal 2.3.2, right?
Your 2nd problem (side note) - the $StateID variable in month.php
If this variable is set BEFORE the require 'views/retrieve.php'; statement on line 59, then you can access this variable in the retrieve.php script, provided you have declared this variable as a global in the retrieve.php script on line 24! (Retrieve is a function with it's own variable scope; if you want to use an external variable, it must be declare thru a "global" statement).
If the $StateID variable is set AFTER the  require 'views/retrieve.php'; statement on line 59, it obviously is not available to the retrieve function.

Your 1st question - the query for retrieving data from the database
On line 28 $q0 (query part 0) is defined. This is the definition of the common part of the MySQL query for both non-recurring and recurring events which is going to be used later.
For non-recurring events, on line 62 three AND statements and an ORDER statement are added to the query (I assume you know that $q1 = $q0."blablabla" means $q1 = <the contents of $q1> appended by "blablabla". So after line 67, $q1 contains: "SELECT d.s_date, d.e_date, . . . . etc . . . ORDER BY d.s_date". (For recurring events the same aplies, the AND statements however, are different.
So if you want to add if statements, which are identical for recurring and non-recurring events, you should just after line 58 add AND or OR statements to select the result set you want to receive from the database.
Example (just after line 58):
if (your condition) {
  $q0 = $q0.
  "AND e.venue = 'New York' ";

Programming is fun ain't it?
Posted:  01 Mar 2011 00:36
I Am using: LuxCal 2.3.2
Yeah the global ha.. did'nt realize retrieve was a function. figured since it was included. if the variable was set before then it would be recognized.. So thanks for clearing that up.

as far as the if statement. you've been very informative thank you.. line 63 is actually where i have been trying to put the if statement.. (once i get one working the rest will be easy) .. after trying as many different ways/things i could think of. i've gotten 2 results. 1 there is a syntax error.. or 2. there is nothing but the header (but no syntax error) ..

i am thinking since thats between: $q1 = $q0."  ... and d.s_date"; (the opening and closing of the quotes for the variable result/definition/meaning.. i'm thinking that the variable does'nt like to have if statements inside of the quotation marks. So I guess i'm having problems breaking out of the variable " 's adding the if statement, then going back to finish what the variable should be.. 

or would it be better to set a variable that holds the AND statement in it. then
adding that variable to the $q1 .. like: $q1 = $q0 . $ST." ?

haha and yeah Programing is great fun.. But i'm also glad you're willing to help.
Posted:  01 Mar 2011 13:31
I actually think i finally got it to work. yey.. thank you =]. (using the 2nd method I thought of, while typing the previous reply). you're using things in the code, i've never seen before, so i guess i'm even learning from it. and that's great. thanks again.