Wednesday, February 18, 2009

Module to backup drupal site

Backup and Migrate Module[http://drupal.org/project/backup_migrate]. is to take backup your drupal site. :)

R.Navaneethakrishnan

Drupal user table : Users list joined before a week

Drupal stores dates in Unix time format. To find email addresses for users who joined after a certain date Use SQL query in phpmyadmin and then exported into an OpenOffice spreadsheet:

SELECT mail, FROM_UNIXTIME(created) FROM users WHERE created > 1199145600 LIMIT 500;

That returns 500 emails from users who registered since January 1, 2008. The FROM_UNIXTIME(created) converts the Unix formatted time into something human-readable.

Thursday, February 12, 2009

Effective Sample code to get category tree in drupal or php

<?php
echo '<select name="category">
<option value="0">Root</option>';
echo $allcats = getTree();
foreach($allcats as $key=>$value) {
echo "<option value='$key'>$value</option>";
}
echo '</select>';
$con = mysql_connect("localhost","root","password") or die();
mysql_select_db('test',$con)or die();
function getTree($id=0) {
static $cates = array();
static $times = 0;
$times++;

$result = mysql_query("SELECT category_id,category_name FROM recusrsive WHERE parent_id=$id ORDER BY category_name") or die();
while($row = mysql_fetch_assoc($result))
{
$cates[$row['category_id']] = str_repeat("&nbsp;&nbsp; ",$times-1)."|-".$row['category_name'];
getTree($row['category_id']);
}
$times--;
return $cates;
}
?>




Table Content

category_id parent_id category_name
1 0 CMS
2 0 Blogs
3 0 Forums
4 0 E-Commerce
5 1 Joomla
6 1 Mambo
7 6 Templates
8 6 Mods/Components
9 4 OSCommerce
10 2 Wordpress
11 10 Themes
12 10 Plugins

Wednesday, February 11, 2009

To add taxonomy in drupal custom form.

By using taxonomy_form() we can form a texonomy in form.

For Ex:
$vid=4;
$category1 = taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy');
$form['taxonomy_info']['taxonomy1'] = array(
'#type' => 'select',
'#title' => t('Terms for the Website'),
'#options' => $category1,
'#description' => t('Website category'),
);

R.Navaneethakrishnan
http://navaneethakrishnan-drupal.blogspot.com/