This topic is locked
[SOLVED]

 Create array to use in "Before SQL query"

10/15/2013 6:59:10 PM
PHPRunner General questions
C
copper21 author

Hello,
This is probably really simple, but I can't figure it out. I have a rather simple query in "List Page: Before Process":
global $conn;

$strSQLSelect = "SELECT eventid FROM events_eligibility_list WHERE userid = '".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSQLSelect ,$conn);

while($data =db_fetch_array($rsSelect))

{

SOMETHING?

}
I need to query all of the eventids from the logged in user and make an array with it and then use "IN" in the WHERE statement in List Page: Before SQL Query.
So, in Before Process, the query will get all of the eventid's from the logged in user from the events_eligibility_list table. Then an array will be created in this format: (doing some imploding/exploding?)
('5','10','21','35') ....assuming this logged in user has 4 records in the events_eligibility_list table.
I then need to use this array using a session variable in the List Page: Before SQL Query page:
$strWhereClause = whereAdd($strWhereClause, "(eventid IN '(' + $_SESSION['array'] + ')' ");
Thank you in advance once again!
Brian

C
cgphp 10/17/2013

In the "List page: Before process" event:

global $conn;

$strSQLSelect = "SELECT eventid FROM events_eligibility_list WHERE userid = '".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSQLSelect ,$conn);

while($data = db_fetch_array($rsSelect))

{

$_SESSION['events'][] = $data['eventid'];

}


In the "List Page: Before SQL Query" event:

$events = implode(",", $_SESSION['events']);

$strWhereClause = whereAdd($strWhereClause, "eventid IN (" . $events . ")");


I'm assuming eventid is integer type.