Answers.Body: <p>I'd recommend looking into using the CiviCRM API as a more robust way to query CiviCRM data.</p>
  <ul>
  <li><a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API" rel="nofollow noreferrer">Using the CiviCRM API</a></li>
  </ul>
  <h2>Check out the API explorer</h2>
  <p>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.</p>
  <p>For the Drupal CiviCRM demo site at <code>http://dmaster.demo.civicrm.org</code>, the API explorer is at <code>http://dmaster.demo.civicrm.org/civicrm/api/explorer</code>. The <a href="https://civicrm.org/demo" rel="nofollow noreferrer">CiviCRM demo sites</a> permit you to log in and explore CiviCRM, though you've obviously got a local install (which may not be Drupal).</p>
  <p>Using the API explorer, you can build a query which matches your code above in SQL, by selecting:</p>
  <ul>
  <li>Entity = Campaign</li>
  <li>Action = get</li>
  <li>Parameter: Campaign created by, (contact)</li>
  </ul>
  <p>The API explorer will show you sample code in PHP, Javascript, and for other interfaces.</p>
  <h2>API query to match the above</h2>
  <p>The equivalent PHP code for the above generated by the API explorer is,</p>
  <pre><code>$result = civicrm_api3('Campaign', 'get', array(
    'sequential' =&gt; 1,
    'created_id' =&gt; $contact_id,
  ));
  </code></pre>
  <p>The <code>$result</code> of this is in the CiviCRM API response format (documentation), which you will iterate through the <code>values</code> of.</p>
  <ul>
  <li><a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API#UsingtheAPI-RequestFormat" rel="nofollow noreferrer">CiviCRM API request format documentation</a></li>
  <li><a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API#UsingtheAPI-ResponseFormat" rel="nofollow noreferrer">CiviCRM API response format documentation</a></li>
  </ul>
  <h2>Why use the API over SQL?</h2>
  <blockquote>
  <p>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?</p>
  <p>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.</p>
  </blockquote>
  <ul>
  <li><a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API#UsingtheAPI-WhyusetheAPI?" rel="nofollow noreferrer">CiviCRM API docs - Why use the API?</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-26T00:31:18.180Z
Answers.LastActivityDate: 2016-02-26T00:31:18.180Z
Answers.LastEditDate: 2020-06-17T09:00:50.810Z
Answers.UserDisplayName: Chris Burgess
Body: <pre><code>function contactcampaign_civicrm_dashboard( $contactID, &amp;$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 ='&lt;table&gt;';
  $campaignList .= '&lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Contribution Page / Event&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;th&gt;Target Amount&lt;/th&gt;&lt;th&gt;Amount Raised&lt;/th&gt;&lt;th&gt;Number of Contributors&lt;/th&gt;&lt;/tr&gt;';
  
  while ($campaigns-&gt;fetch()) {
  
   foreach($campaigns as $campaign){
  
      $title = $campaign-&gt;title;
      $targetAmount = $campaign-&gt;goal_general;
      $raisedAmount = $campaign-&gt;goal_revenue;
       $status = $campaign-&gt;status_id-&gt;title;
       $parent = $campaign-&gt;parent_id-&gt;title;
  
      $campaignList .=  '&lt;tr&gt;';
      $campaignList .=  '&lt;td&gt;'.$title.'&lt;/td&gt;';
      $campaignList .=  '&lt;td&gt;'.$targetAmount.'&lt;/td&gt;';
      $campaignList .=  '&lt;td&gt;'.$raisedAmount.'&lt;/td&gt;';
       $campaignList .= '&lt;td&gt;'.$status.'&lt;/td&gt;';
       $campaignList .= '&lt;td&gt;'. $parent.'&lt;/td&gt;';
      $campaignList .=  '&lt;/tr&gt;';
   }
  };
  $campaignList .= '&lt;/table&gt;';
  
  return array (
     'Campaign List'=&gt; $campaignList
  );
  </code></pre>
  
  <p>}</p>
  
  <p>pls i dont know what am doin wrong.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-25T19:17:02.627Z
Comments.Text: 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.
Comments.UserDisplayName: William Mortada
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-26T04:36:13.533Z
Comments.Text: @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
Comments.UserDisplayName: Akoh  Victor Gutz
Tags: <civicrm-entity><civicrm-buildkit>
Title: Building an extention in civicrm. i try fetch campaign base on contact nothing displays while i have records
ThreadText: # Building an extention in civicrm. i try fetch campaign base on contact nothing displays while i have records
  
  (Asked by: username_0 on 2016-02-25)
  
  ```
  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.
  
  **Tags:** civicrm-entity, civicrm-buildkit
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: @username_1 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  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-02-26. Score: 2
  
  I'd recommend looking into using the CiviCRM API as a more robust way to query CiviCRM data.
  
  * [Using the CiviCRM API](https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API)
  
  ## 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](https://civicrm.org/demo) 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.
  
  * [CiviCRM API request format documentation](https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API#UsingtheAPI-RequestFormat)
  * [CiviCRM API response format documentation](https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API#UsingtheAPI-ResponseFormat)
  
  ## 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.
  
  * [CiviCRM API docs - Why use the API?](https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API#UsingtheAPI-WhyusetheAPI?)
  
  
  ---
  
  