This topic is locked

Filtering list page by passed variable

1/24/2008 2:10:33 PM
PHPRunner General questions
jwoker author

I would like to filter my list results by one of two variables, either job.id or job.job_name and i am trying a previously posted solution but can't get it to work.
I just get a list of all records when I link to something like http://...Jobs_list.php?job_name=CO07-1105

or http://...Jobs_list.php?id=103
with a 'List page: before SQL query' event of :
//** Custom code ****

// put your custom code here
if(@$_POST["id"])

$strWhereClause=whereAdd($strWhereClause,"job.id = ".$_POST["id"]);
if(@$_POST["job_name"])

$strWhereClause=whereAdd($strWhereClause,"job.job_name = ".$_POST["job_name"]);
//***
My SQL is:
select `job`.`id`,

`job`.`id` as id2,

`job`.`job_name`,

`job`.`status`,

`job`.`cus_id`,

`job`.`sr_id`,

`job`.`cnv_id`,

`job`.`pm_id`,

`job`.`evaluator_id`,

`job`.`sale_date`,

concat(`job`.`addr1`,' ',`job`.`addr2`,' ', `job`.`city`,' ',`job`.`state`,' ',`job`.`zip`) as location,

`job`.`addr1`,

`job`.`addr2`,

`job`.`city`,

`job`.`state`,

`job`.`zip`,

`job`.`discount`,

`job`.`ins_name`,

`job`.`ins_phone`,

`job`.`ins_fax`,

`job`.`ins_email`,

`job`.`ins_adjuster`,

`job`.`ins_policy_num`,

`job`.`ins_claim_num`,

`job`.`notes`,

`job`.`assign_sr`,

`job`.`assign_evaluator`,

`job`.`assign_sm`,

`job`.`assign_acct`,

`job`.`high`,

`job`.`stories`,

`job`.`steep`,

`job`.`bad_access`,

`job`.`roof_pitch`,

`job`.`shingle_manufacturer`,

`job`.`shingle_prod`,

`job`.`shingle_color`,

`job`.`shingle_type`,

CONCAT_WS(', '

, `customer`.`lastName`

, `customer`.`firstName`

, `customer`.`phone_main`

, `customer`.`email` ) AS customer

, `totals`.`total_payments`

, `totals`.`type_2`

  • `job`.`adjuster_price` AS total_settlement

    , `totals`.`type_2`
  • `job`.`adjuster_price`

- `job`.`discount`

- `totals`.`total_payments` AS balance_due

FROM `job`

INNER

JOIN `customer`

ON `customer`.`id` = `job`.`cus_id`

LEFT OUTER

JOIN ( SELECT `job`

, SUM( CASE WHEN `t`.`category`='payment'

THEN `t`.`amount` ELSE 0 END ) AS total_payments

, SUM( CASE WHEN `t`.`type`= 2

THEN `t`.`amount` ELSE 0 END ) AS type_2

FROM `job_transactions` AS t

GROUP

BY `job`

) AS totals

ON `totals`.`job` = `job`.`id`

A
alang 1/24/2008

I restrict the list view by operating directly on the strSQL parameter of the before SQL query event using the AddWhere function in commonfunctions.php module. ie
$strSQL=AddWhere($strSQL,"job.id = ".$_POST["id"]);

jwoker author 1/26/2008

That doesn't work for me either and i have tried these approaches on other list pages without success.
Any ideas how to trouble shoot what is going wrong?

jwoker author 1/28/2008

I tried creating a new project and using the above methods for limiting the list page with no success.
I am using 4.1 build 320.
Any help would be appreciated.

J
Jane 1/29/2008

Hi,
try to use this code:

if(@$_GET["id"])

$strWhereClause=whereAdd($strWhereClause,"job.id = ".$_GET["id"]);
if(@$_GET["job_name"])

$strWhereClause=whereAdd($strWhereClause,"job.job_name = ".$_GET["job_name"]);

jwoker author 1/29/2008

Still having problems. It may have to do with the complexity of my sql but i need to find a solution.
This code:

[quote]if(@$_GET["id"])

$strWhereClause=whereAdd($strWhereClause,"job.id = ".$_GET["id"]);
Produced this error:

Error 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 ') AS totals ON `totals`.`job` = `job`.`id` where job.id = 105' at line 1

URL www.automatedroofing.com/sales241/Jobs_list.php?id=105

Error file /home/automate/public_html/sales241/include/dbconnection.php

Error line 26

SQL query select `job`.`id`, `job`.`id` as id2, `job`.`job_name`, `job`.`status`, `job`.`cus_id`, `job`.`sr_id`, `job`.`cnv_id`, `job`.`pm_id`, `job`.`evaluator_id`, `job`.`sale_date`, concat(`job`.`addr1`,' ',`job`.`addr2`,' ', `job`.`city`,' ',`job`.`state`,' ',`job`.`zip`) as location, `job`.`addr1`, `job`.`addr2`, `job`.`city`, `job`.`state`, `job`.`zip`, `job`.`discount`, `job`.`ins_name`, `job`.`ins_phone`, `job`.`ins_fax`, `job`.`ins_email`, `job`.`ins_adjuster`, `job`.`ins_policy_num`, `job`.`ins_claim_num`, `job`.`notes`, `job`.`assign_sr`, `job`.`assign_evaluator`, `job`.`assign_sm`, `job`.`assign_acct`, `job`.`high`, `job`.`stories`, `job`.`steep`, `job`.`bad_access`, `job`.`roof_pitch`, `job`.`shingle_manufacturer`, `job`.`shingle_prod`, `job`.`shingle_color`, `job`.`shingle_type`, CONCAT_WS(', ' , `customer`.`lastName` , `customer`.`firstName` , `customer`.`phone_main` , `customer
and this code:

if(@$_GET["job_name"])

$strWhereClause=whereAdd($strWhereClause,"job.job_name = ".$_GET["job_name"]);
Produced this error:

Error description Unknown column 'CO08' in 'where clause'

URL www.automatedroofing.com/sales241/Jobs_list.php?job_name=CO08-1101

Error file /home/automate/public_html/sales241/include/dbconnection.php

Error line 26

SQL query select `job`.`id`, `job`.`id` as id2, `job`.`job_name`, `job`.`status`, `job`.`cus_id`, `job`.`sr_id`, `job`.`cnv_id`, `job`.`pm_id`, `job`.`evaluator_id`, `job`.`sale_date`, concat(`job`.`addr1`,' ',`job`.`addr2`,' ', `job`.`city`,' ',`job`.`state`,' ',`job`.`zip`) as location, `job`.`addr1`, `job`.`addr2`, `job`.`city`, `job`.`state`, `job`.`zip`, `job`.`discount`, `job`.`ins_name`, `job`.`ins_phone`, `job`.`ins_fax`, `job`.`ins_email`, `job`.`ins_adjuster`, `job`.`ins_policy_num`, `job`.`ins_claim_num`, `job`.`notes`, `job`.`assign_sr`, `job`.`assign_evaluator`, `job`.`assign_sm`, `job`.`assign_acct`, `job`.`high`, `job`.`stories`, `job`.`steep`, `job`.`bad_access`, `job`.`roof_pitch`, `job`.`shingle_manufacturer`, `job`.`shingle_prod`, `job`.`shingle_color`, `job`.`shingle_type`, CONCAT_WS(', ' , `customer`.`lastName` , `customer`.`firstName` , `customer`.`phone_main` , `customer

J
Jane 1/30/2008

Hi,
you can publish your project on Demo Account and post a URL to your pages here or send it to [email=support@xlinesoft.com]support@xlinesoft.com[/email] along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.