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 CiviReport (Moderator: Dave Greenberg) »
  • Need example of doing "UNION" within CiviReport
Pages: [1]

Author Topic: Need example of doing "UNION" within CiviReport  (Read 1053 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Need example of doing "UNION" within CiviReport
March 19, 2011, 08:58:56 pm
I am in the process of writing a new custom report. 

I have already written and tested my SQL query ( which uses a UNION clause  against CiviPledge and the CiviContribute tables) using PhpMyAdmin and it works as expected.

But I am struggling to get this working in my CiviReport. All the other report examples I have looked at use a single SELECT clause in their query, built in the function named "select( ) ".

Is there an example of a report that uses a UNION cluase that I could look at?


Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Need example of doing "UNION" within CiviReport
March 19, 2011, 09:37:52 pm
I don't think that currently any report that uses UNION clause. U need to override some function like select( ), from(), where() within your report and accordingly need to build the query.
variable $this->_columnHeaders is responsible to build report result columns.
Also Function alterRows( ), might help you to tweak the report result (ie display rows ) accordingly.

Rajan

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: Need example of doing "UNION" within CiviReport
March 20, 2011, 07:33:15 am

hey sarah:

implement your own

Code: [Select]
function buildQuery

instead of the select/where/from clauses. The framework will call that function and u can embed ant complex sql in there

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Need example of doing "UNION" within CiviReport
March 20, 2011, 11:01:33 pm
Thanks! That did the trick.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Need example of doing "UNION" within CiviReport

This forum was archived on 2017-11-26.