This topic is locked
[SOLVED]

 Syntax for Replace Query in BeforeQueryList

9/3/2011 12:12:02 PM
PHPRunner General questions
P
procheck author

Hi,
From what I've read, Unions can be created in the BeforeQueryList event but I've been unable to make it work (ver5.3). This UNION is tested and it works.
So for example:
SELECT FROM tablename1 where....
UNION ALL
SELECT
FROM tablename2 where....
Does anyone know the correct syntax for this in BeforeQueryList?
Thank-you!
Al

C
cgphp 9/3/2011
$strSQL = "SELECT * FROM tablename1 WHERE .... UNION ALL SELECT * FROM tablename2 WHERE ....";



Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order. More info here: http://www.w3schools.com/sql/sql_union.asp

P
procheck author 9/3/2011

Hi Christian,
As I previously stated, this is a UNION that is tested and it works elsewhere in PHPRunner. I am now trying to apply it in the List page.
As a simple test to get the syntax working, I copied the SQL from the Query tab so for sure that works.
$strSQL1 =

"SELECT

players_chosen.record_id,

players_chosen.PlayerID,

players_chosen.UserName,

player_name.FirstName,

player_name.LastName

...

FROM players_chosen

INNER JOIN player_name ON players_chosen.PlayerID = player_name.PlayerID

WHERE (GameDate = (SELECT MAX(B.GameDate) FROM player_name 'B'))

ORDER BY players_chosen.PlayerID";
$strSQL = whereAdd($strSQL, "$strSQL1");
I assuming that my whereAdd syntax is incorrect?
Thanks
Al

C
cgphp 9/3/2011

I don't understand. Do you want to add a where clause ? whereAdd doesn't perform a UNION. The UNION operator is used to combine the result-set of two or more SELECT statements. What are the two tables ?

P
procheck author 9/3/2011

From what I've read, any SQL can be replaced in BeforeQueryList. Maybe this is incorrect?
I don't need the syntax for a UNION. This I know how to do. The manual is vague on how to use $strSQL.
I've also tried the code below but I always get an error.
$rs = db_query($strSQL,$conn);

$data=db_fetch_array($rs);
I just want to know the syntax used in PHPRunner to use $strSQL.
Hopefully this is more clear.

C
cgphp 9/3/2011

$strSQL is executed by PHPrunner. You have only to set the query:

$strSQL = "SELECT * FROM table_name WHERE .....";
P
procheck author 9/3/2011

I didn't realize it was that simple. It works now.
Thanks Chritian!
Al