Monday, January 13, 2014

Select Query with multiple conditions

Like we use

Select * from tablename where this=that and this=that

we can do same in Drupal7 as follows

 $query1 = db_select('field_data_field_coupon_date1','f')->fields('f')->condition('entity_id',$enitiy_id,'=')->condition('revision_id',$revision_id,'=')->condition('field_coupon_date1_value',$date,'='); 
$result1 = $query1->execute();
$row1 = $result1->fetchAssoc();

Select Query with a condition , Limit and Order By Clause Drupal 7

$query = db_select('opinions','o')->fields('o')->condition('approved','Yes','=')->condition('bid',$node->nid,'=')->orderBy('opinion_id', 'DESC')->range(0,3); 
$result = $query->execute();
$row = $result->fetchAssoc();
print_r(($row); // to view all fields name
print $row['uid'];

Using Jquery In Drupal

<script>
(function($){
//Inside this write your jquery document.ready function

   $(document).ready(function()
{
$("#simple-post").click(function()
{
//alert('Form submitted');
$("#ajaxform").submit(function(e)
{
$("#simple-msg").html("<img src='loading.gif'/>");
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR) 
{
//alert('Success');
$("#simple-msg").html('<pre><code class="prettyprint">'+data+'</code></pre>');

},
error:function(jqXHR, textStatus, errorThrown) 
{
alert('Failure');
$("#simple-msg").html('<pre><code class="prettyprint">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
   e.preventDefault(); //STOP default action
});

$("#ajaxform").submit(); //SUBMIT FORM
});
}); 


})(jQuery);
</script>

Wednesday, January 8, 2014

Learn Drupal: Getimage name for media field selector filed Drupa...

Learn Drupal: Getimage name for media field selector filed Drupa...: 1st got to admin  /admin/structure/types/manage/your-content-type/display change the  Format of media file selector field to rendered file ...

Getimage name for media field selector filed Drupal 7

1st got to admin /admin/structure/types/manage/your-content-type/display change the Format of media file selector field to rendered file
Fig 1.0 Fig 1.1 Fig 1.2



and place this code in yout tpl

$node = node_load($row['nid']);  

for($i=0;$i<count($node->your-field-name['und']);$i++) {
   //your file name
    print $node->field_product_images['und'][$i]['filename'];

}