This topic is locked

Problems with beforequerylist event

11/5/2007 12:55:29 PM
PHPRunner General questions
M
Max68 author

In the event beforequerylist i've added the code:
$strWhereClause="operator='MC'";
to let me filter automatically the data on list load.
the query work correctly, but after, in the list page, if I want to do search by other fields this don't works.
How can solve this problem?
thanks

M
Max68 author 11/5/2007

I've find another problem, the export page and the printer-friendly page are indipendent from the code put on the beforequerylist!
Can anybody try to solve this problem or explain me how to do?

Sergey Kornilov admin 11/5/2007

Use the following:

$strWhereClause= AddWhere($strWhereClause, " operator='MC' ");
M
Max68 author 11/5/2007

Use the following:


$strWhereClause= AddWhere($strWhereClause, " operator='MC' ");


I've put the following code

$strWhereClause= AddWhere($strWhereClause, "d.`operator`='MC' ");
I've the following error

Error type 256

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where d.`operator`='MC' group by d.`operator`, d.`commessa`, d.`Anno`' at line 1

Sergey Kornilov admin 11/5/2007

Show me the whole SQL query.

M
Max68 author 11/5/2007

Show me the whole SQL query.


SELECT d.`commessa`,

d.`cliente`,

d.`operatore`,

d.`Anno`,

(

Select

sum(pr.giornate)

from (

SELECT f.`cod_operatore` As operatore,

f.`cod_commessa`As commessa,

year (f.`data`) As Anno,

sum(f.`gg`) As giornate

FROM db_innovare2.rapportinogiornaliero f

group by f.`cod_operatore`,

f.`cod_commessa`,

year (f.`data`)

) pr

where pr.`Anno`< d.`Anno`

AND pr.`operatore`=d.`operatore`

AND pr.`commessa`=d.`commessa`

) As prec,

Sum(CASE d.`Mese` WHEN '1' THEN d.`giornate` ELSE 0 END) As Gennaio,

Sum(CASE d.`Mese` WHEN '2' THEN d.`giornate` ELSE 0 END) As Febbraio,

Sum(CASE d.`Mese` WHEN '3' THEN d.`giornate` ELSE 0 END) As Marzo,

Sum(CASE d.`Mese` WHEN '4' THEN d.`giornate` ELSE 0 END) As Aprile,

Sum(CASE d.`Mese` WHEN '5' THEN d.`giornate` ELSE 0 END) As Maggio,

Sum(CASE d.`Mese` WHEN '6' THEN d.`giornate` ELSE 0 END) As Giugno,

Sum(CASE d.`Mese` WHEN '7' THEN d.`giornate` ELSE 0 END) As Luglio,

Sum(CASE d.`Mese` WHEN '8' THEN d.`giornate` ELSE 0 END) As Agosto,

Sum(CASE d.`Mese` WHEN '9' THEN d.`giornate` ELSE 0 END) As Settembre,

Sum(CASE d.`Mese` WHEN '10' THEN d.`giornate` ELSE 0 END) As Ottobre,

Sum(CASE d.`Mese` WHEN '11' THEN d.`giornate` ELSE 0 END) As Novembre,

Sum(CASE d.`Mese` WHEN '12' THEN d.`giornate` ELSE 0 END) As Dicembre,

(Sum(d.`giornate`)+

IF (

(Select sum(pr2.giornate)

from (

SELECT f2.`cod_operatore` As operatore,

f2.`cod_commessa`As commessa,

year (f2.`data`) As Anno,

sum(f2.`gg`) As giornate

FROM db_innovare2.rapportinogiornaliero f2

group by f2.`cod_operatore`,

f2.`cod_commessa`,

year (f2.`data`)

) pr2

where pr2.`Anno`< d.`Anno`

AND pr2.`operatore`=d.`operatore`

AND pr2.`commessa`=d.`commessa`

)IS NULL, 0,

(Select sum(pr3.giornate)

from (

SELECT f3.`cod_operatore` As operatore,

f3.`cod_commessa`As commessa,

year (f3.`data`) As Anno,

sum(f3.`gg`) As giornate

FROM db_innovare2.rapportinogiornaliero f3

group by f3.`cod_operatore`,

f3.`cod_commessa`,

year (f3.`data`)

) pr3

where pr3.`Anno`< d.`Anno`

AND pr3.`operatore`=d.`operatore`

AND pr3.`commessa`=d.`commessa`

)

)

) As totali,

(

SELECT sum(cai.`n_giorni`)

FROM commesse_ai cai

where cai.`cod_operatore`=d.`operatore`

AND cai.`cod_commessa`=d.`commessa`

group by cai.`cod_operatore`,

cai.`cod_commessa`) As Contr,

(

(

SELECT sum(cai.`n_giorni`)

FROM commesse_ai cai

where cai.`cod_operatore`=d.`operatore`

AND cai.`cod_commessa`=d.`commessa`

group by cai.`cod_operatore`,

cai.`cod_commessa`)-

(

Sum(d.`giornate`)+

IF (

(Select sum(pr2.giornate)

from (

SELECT f2.`cod_operatore` As operatore,

f2.`cod_commessa`As commessa,

year (f2.`data`) As Anno,

sum(f2.`gg`) As giornate

FROM db_innovare2.rapportinogiornaliero f2

group by f2.`cod_operatore`,f2.`cod_commessa`,

year (f2.`data`)

) pr2

where pr2.`Anno`< d.`Anno`

AND pr2.`operatore`=d.`operatore`

AND pr2.`commessa`=d.`commessa`

)IS NULL,

0,

(Select sum(pr3.giornate)

from (

SELECT f3.`cod_operatore` As operatore,

f3.`cod_commessa`As commessa,

year (f3.`data`) As Anno,

sum(f3.`gg`) As giornate

FROM db_innovare2.rapportinogiornaliero f3

group by f3.`cod_operatore`,

f3.`cod_commessa`,

year (f3.`data`)

) pr3

where pr3.`Anno`< d.`Anno`

AND pr3.`operatore`=d.`operatore`

AND pr3.`commessa`=d.`commessa`

)

)

)

) As restanti

FROM (

SELECT r.`cod_operatore` As operatore,

r.`cod_commessa`As commessa,

r.`cliente` As cliente,

year (r.`data`) As Anno,

month(r.`data`) As Mese,

sum(r.`gg`) As giornate

FROM db_innovare2.rapportinogiornaliero r

group by r.`cod_operatore`,r.`cod_commessa`,year (r.`data`)

) d

group by d.`operatore`,

d.`commessa`,

d.`Anno`

M
Max68 author 11/6/2007

Show me the whole SQL query.


I don't know if this can help you to solve the problem:
I've created a simple query:
select `id`,

`area`,

`capo`,

`
inserted_on`,

`timestamp`

From `aree`
I've put in the BeforeQueryList Event the follow code:

$strWhereClause= AddWhere($strWhereClause, "capo='MC';");

(tried also "$strWhereClause= AddWhere($strWhereClause, "`capo`='MC';")<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23032&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />
I've the follow error message:

Description

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where capo='MC'' at line 1

Query SQL

Query SQLselect `id`, `area`, `capo`, `inserted_on`, `
timestamp` From `aree` where where capo='MC';
I've seen the word "Where" in inserted twice.

M
Max68 author 11/6/2007

For all that have my same problems:

I think that the function whereAdd (in the beforequerySQL event) doesn't work correctly so i have made this:
in the initial query I've added a where option that permits all data (e.g. _id>0) like this:

select `id`,

`area`,

`capo`,

`
inserted_on`,

`timestamp`

From `aree`

where `
id`>0
then in the beforequerylist i've inserted the whereadd function (that works correctly) like the following code:
$strWhereClause= whereAdd($strWhereClause, "capo='MC';");
And the list page is loaded as i want.
Attention: you must repeat this code also in the beforequerySQL events of Printer-friendly page and in the Export page to complete the work
I hope this not create a problem for phprunner developers because i think that phprunner is a valid product
Massimiliano