CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom Search Systax error in String variable.
Pages: [1]

Author Topic: Custom Search Systax error in String variable.  (Read 1073 times)

Cedeira

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 1
    • CompuLogiX Systems, Inc.
Custom Search Systax error in String variable.
November 14, 2008, 08:40:36 pm
Hi all,

I am creating a custom search and I keep on getting a syntax error in the following $select variable. I know it has to do with the fact that the select I am inserting in it is escaping it and breaking into a new string or something like that. I am not familiar with how PHP works when building these types of variables.

The error thrown is "Parse error: syntax error, unexpected T_STRING in xxxxxxx, line 110". Line 110 is the line with the bold "(SELECT DISTINCT". I tested this SQL statement in my SQL Query editor and it worked like a charm.

Code: [Select]
        // SELECT clause must include contact_id as an alias for civicrm_contact.id

        $select  = "
DISTINCT (cOrg.ID) as contact_id, (cOrg.sort_name) AS Team, (cOrg.nick_name) AS Flight,
(cRT.name_b_a) as Role, (cInd.display_name) as Name, (cPh.Phone) AS Phone,
[b](SELECT DISTINCT[/b] (cPh2.Phone) FROM civicrm_phone cPh2 where cPh2.contact_id = cInd.id and cPh2.Phone_Type = "Mobile") AS Mobile,
(SELECT DISTINCT (cPh3.Phone) FROM civicrm_phone cPh3 where cPh3.contact_id = cInd.id and cPh3.Phone_Type = "Fax") AS Fax
";

Any help is appreciated.

thanks,
Jose
God grant me the serenity to accept the things I can not change, valor to change the ones I can, and the knowledge to recognize the difference!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom Search Systax error in String variable.
November 15, 2008, 11:39:14 am

thats a php error. Note you have double quotes within double quotes. I would rewrite it as:

Code: [Select]
$select  = "
DISTINCT (cOrg.ID) as contact_id, (cOrg.sort_name) AS Team, (cOrg.nick_name) AS Flight,
(cRT.name_b_a) as Role, (cInd.display_name) as Name, (cPh.Phone) AS Phone,
(SELECT DISTINCT (cPh2.Phone) FROM civicrm_phone cPh2 where cPh2.contact_id = cInd.id and cPh2.Phone_Type = \"Mobile\") AS Mobile,
(SELECT DISTINCT (cPh3.Phone) FROM civicrm_phone cPh3 where cPh3.contact_id = cInd.id and cPh3.Phone_Type = \"Fax\") AS Fax
";
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Cedeira

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 1
    • CompuLogiX Systems, Inc.
Re: Custom Search Systax error in String variable.
November 16, 2008, 01:31:35 pm
That fixed it. Thanks Lobo.
God grant me the serenity to accept the things I can not change, valor to change the ones I can, and the knowledge to recognize the difference!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom Search Systax error in String variable.

This forum was archived on 2017-11-26.