Building an extention in civicrm. i try fetch campaign base on contact nothing displays while i have records
I'd recommend looking into using the CiviCRM API as a more robust way to query CiviCRM data.

Using the CiviCRM 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 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' =&gt; 1,
  'created_id' =&gt; $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
CiviCRM API response format documentation

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?