function contactcampaign_civicrm_dashboard( $contactID, &$contentPlacement ) {
// REPLACE Activity Listing with custom content
$contentPlacement = 3;
//(int) CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) FROM civicrm_campaign');
$query = "SELECT id, title, parent_id, status_id, goal_general, goal_revenue
              FROM civicrm_campaign
              WHERE created_id = $contactID";
$campaigns = CRM_Core_DAO::executeQuery($query);

$campaignList ='<table>';
$campaignList .= '<tr><th>Title</th><th>Contribution Page / Event</th><th>Status</th><th>Target Amount</th><th>Amount Raised</th><th>Number of Contributors</th></tr>';

while ($campaigns->fetch()) {

 foreach($campaigns as $campaign){

    $title = $campaign->title;
    $targetAmount = $campaign->goal_general;
    $raisedAmount = $campaign->goal_revenue;
     $status = $campaign->status_id->title;
     $parent = $campaign->parent_id->title;

    $campaignList .=  '<tr>';
    $campaignList .=  '<td>'.$title.'</td>';
    $campaignList .=  '<td>'.$targetAmount.'</td>';
    $campaignList .=  '<td>'.$raisedAmount.'</td>';
     $campaignList .= '<td>'.$status.'</td>';
     $campaignList .= '<td>'. $parent.'</td>';
    $campaignList .=  '</tr>';
$campaignList .= '</table>';

return array (
   'Campaign List'=> $campaignList


pls i dont know what am doin wrong.

  • Thanks for your post. You are more likely to get a response if you provide a bit more detail about what you are trying to do. Feb 25 '16 at 19:17
  • @william am creating a CiviCRM contact tab: Displays a list of the personal campaign pages that a contact has created. The tab shows the personal campaign page title (with a link to the page), status, contribution page or event that it is funding for, no of contributions, amount raised, target amount and a link to the edit page form Feb 26 '16 at 4:36

I'd recommend looking into using the CiviCRM API as a more robust way to query CiviCRM data.

Check out the API explorer

In your CiviCRM instance you can access the API Explorer. It includes tools to visually generate API queries which would deliver what you're doing there.

For the Drupal CiviCRM demo site at http://dmaster.demo.civicrm.org, the API explorer is at http://dmaster.demo.civicrm.org/civicrm/api/explorer. The CiviCRM demo sites permit you to log in and explore CiviCRM, though you've obviously got a local install (which may not be Drupal).

Using the API explorer, you can build a query which matches your code above in SQL, by selecting:

  • Entity = Campaign
  • Action = get
  • Parameter: Campaign created by, (contact)

The API explorer will show you sample code in PHP, Javascript, and for other interfaces.

API query to match the above

The equivalent PHP code for the above generated by the API explorer is,

$result = civicrm_api3('Campaign', 'get', array(
  'sequential' => 1,
  'created_id' => $contact_id,

The $result of this is in the CiviCRM API response format (documentation), which you will iterate through the values of.

Why use the API over SQL?

If you're not familiar with APIs, you might ask why you would use the API when you could access the core functions (e.g. the BAO files) or the data in the MySQL database directly?

The answer is that the community will ensure that the API will function as expected with every new release. Great effort is made to preserve backwards compatibility of the API for several versions of CiviCRM. If you decide to use other ways to collect data (like your own MySQL statements), you are left to your own devices. Changes in the schema and BAO arguments, etc. will cause you grief.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.