Wednesday 4 July 2012

How to Fetch Taxonomy Term in Drupal 7


Some time we not able to print value of taxonomy in *.tpl.php page. We can easily print value of a field.

Example

 <?php print $node->field_status_icon[$node->language][0]['value']; ?>

When we do same thing for taxonomy, we found blank content. For taxonomy we can fetch data through simple sql code.

Example

 <?php $result = db_query("select * from taxonomy_term_data where tid='".$node->field_type['und'][0]['tid']."'");
foreach($result as $record)
{
 echo $record->name;
}?>

Complete Code: 

Page—<page name> .tpl.php 

<div class="event_page_mid">
<div class="eventext" >
<?php if($node->field_type['und'][0]['tid']): ?>
<div class="field field-type-options-select field-field-type">
 <h3 class="field-label">Type</h3>
 <div class="field-items">
 <div class="field-item"><?php

 $result = db_query("select * from taxonomy_term_data where tid='".$node->field_type['und'][0]['tid']."'");
foreach($result as $record)
{
 echo $record->name;
}


?><?php //print $node->field_type['und'][0]['tid']; ?></div>
  </div>
</div>
<?php endif; ?>

<?php if($node->field_genre['und'][0]['tid']): ?>
<div class="field field-type-options-select field-field-type">
  <h3 class="field-label">Genre</h3>
  <div class="field-items">
      <div class="field-item">
      <?php

 $resultterm = db_query("select * from taxonomy_term_data where tid='".$node->field_genre['und'][0]['tid']."'");
foreach($resultterm  as $recordnew)
{
 echo $recordnew->name;
}


?>
      <?php //print $node->field_genre['und'][0]['tid']; ?></div>
  </div>
</div>
<?php endif; ?>

Monday 2 July 2012

How to Write Doctrine Query OR conditions

 

See how we can write doctrine query  using multiple OR conditions which will prevent you from the special characters.

Example: 
$query = Doctrine_Query::create()
        ->select('u.*, up.*')
        ->from('sfGuardUser u')
        ->leftJoin('u.Profile up');
        $query->where('u.username LIKE ? OR u.first_name LIKE ? OR u.last_name LIKE ? OR up.fullname LIKE ? OR u.email_address LIKE ? OR up.charity_name LIKE ? OR up.advertiser_name LIKE ? OR up.organization_name LIKE ?',
            array('%'.$input.'%', '%'.$input.'%', '%'.$input.'%', '%'.$input.'%', '%'.$input.'%','%'.$input.'%', '%'.$input.'%', '%'.$input.'%'));