The start with .. connect by clause can be used to select data that has a hierarchical relationship
(usually some sort of parent->child (boss->employee or thing->parts).
We'll see a simple example to understand this,
create table test_connect_by (
parent number,
child number,
constraint uq_tcb unique (child)
);
insert into test_connect_by values ( 5, 2);
insert into test_connect_by values ( 5, 3);
Parent = 5
Child = 2,3
insert into test_connect_by values (15,10);
insert into test_connect_by values (15, 5);
Parent = 15
Child = 10,5
insert into test_connect_by values (17, 9);
insert into test_connect_by values (17, 8);
Parent = 17
Child = 9,8
insert into test_connect_by values (38,15);
insert into test_connect_by values (38,17);
Parent = 38
Child = 15,17
insert into test_connect_by values (26, 1);
insert into test_connect_by values (26,12);
Parent = 26
Child = 1,12
insert into test_connect_by values (null, 38);
insert into test_connect_by values (null, 26);
Parent = null
Child = 38,26
Query:
select lpad(' ',2*(level-1)) || to_char(child) s
from test_connect_by
start with parent is null
connect by prior child = parent;
Output:
38
15
10
5
17
9
8
26
1
12
Thursday, January 13, 2011
Wednesday, January 12, 2011
Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com.
If you want to do same with your website then put the following code to .htaccess file.
CODE:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
Where $1 is the first argument kind of thing like for example if you want to redirect
http://drupal.com/user => http://www.drupal.com/user .
If you want to do same with your website then put the following code to .htaccess file.
CODE:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
Where $1 is the first argument kind of thing like for example if you want to redirect
http://drupal.com/user => http://www.drupal.com/user .
Rewriting URL's with .htaccess
Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
For more reference on this refer:
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
For more reference on this refer:
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
Setting up a Cron tab in Linux:
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Example for scheduling a job for 10th June 08:30 AM
30 08 10 06 * /home/ramesh/full-backup
* 30 – 30th Minute
* 08 – 08 AM
* 10 – 10th Day
* 06 – 6th Month (June)
* * – Every day of the week
For further more details on setting up Cron tabs and viewing the cron tab entries you can refer:
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples
MIN HOUR DOM MON DOW CMD
Example for scheduling a job for 10th June 08:30 AM
30 08 10 06 * /home/ramesh/full-backup
* 30 – 30th Minute
* 08 – 08 AM
* 10 – 10th Day
* 06 – 6th Month (June)
* * – Every day of the week
For further more details on setting up Cron tabs and viewing the cron tab entries you can refer:
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples
Tuesday, January 11, 2011
Writing to a Remote file using FTP functions
$file_name = "data.txt";
$fp = fopen ( $file_name, 'r' );
if ($fp) {
$data = fread ( $fp, filesize ( $file_name ) );
fclose ( $fp );
$file_name = "ftp://user:pass@ftp.somedomain.com/home/user/$file_name";
$fp = fopen ( $file_name, 'wt' );
if ($fp) {
echo 'writing data';
fwrite ( $fp, $data );
fclose ( $fp );
}
}
$fp = fopen ( $file_name, 'r' );
if ($fp) {
$data = fread ( $fp, filesize ( $file_name ) );
fclose ( $fp );
$file_name = "ftp://user:pass@ftp.somedomain.com/home/user/$file_name";
$fp = fopen ( $file_name, 'wt' );
if ($fp) {
echo 'writing data';
fwrite ( $fp, $data );
fclose ( $fp );
}
}
Autosave - Drupal module
The Autosave module automatically saves a snapshot of your content type form using AJAX. If the user's browser or machine dies while editing a node; the edits will be presented to the user the next time they return to the node. The user may toggle back and forth between the last saved version and the version with the edits that were lost and select which of these they would like to continue with.
This is a very useful module in situations like when your machine is corrupted before saving your article or news in these situations this module will have the backup of your content.
You can find this at : http://drupal.org/project/autosave
Database tweaks - Drupal module
This module allow you to enable and change following settings in database:
- SQL_BIG_SELECTS
- MAX_JOIN_SIZE
- MAX_ALLOWED_PACKET
- WAIT_TIMEOUT
and changing SQL_MODES.
This module is very useful in situations like, when the DB is overloaded with too many fields in CCK or very big queries (cache queries) it will throw "mysql gone away" error in drupal. This is actually a common error in these situations. The Fix is we need to increase the Packet size in my.cnf or my.ini file in Mysql folder. But in situations like if in Live sites where we don't have access to these files "my.cnf" if the error comes it will be difficult to handle in those situations you can use this module.
You can find the module at : http://drupal.org/project/db_tweaks
Drupal for Firebug - Drupal module
Drupal for Firebug module:
This module is a helper module for a customized Firefox plugin that displays Drupal debugging and SQL query information. Very Useful module, to checkout the node contents you don't need to put node_load or some functions like this module will load and display all the Node properties and Values through Firebug.
You can find the module at : http://drupal.org/project/drupalforfirebug.
This module is a helper module for a customized Firefox plugin that displays Drupal debugging and SQL query information. Very Useful module, to checkout the node contents you don't need to put node_load or some functions like this module will load and display all the Node properties and Values through Firebug.
You can find the module at : http://drupal.org/project/drupalforfirebug.
Tuesday, March 3, 2009
Taxonomy Functions
Avoid queries to display the content which are associated with a particular taxonomy term or vocabulary.
Try Using the taxonomy related functions like ,
1. taxonomy_get_children
-- Find all children of a term ID.
2. taxonomy_get_parents
-- Find all parents of a given term ID.
3. taxonomy_get_parents_all
-- Find all ancestors of a given term ID.
4. taxonomy_get_related
-- Find all term objects related to a given term ID.
5. taxonomy_get_term
-- Return the term object matching a term ID.
6. taxonomy_get_term_by_name
-- Try to map a string to an existing term, as for glossary use.
7. taxonomy_get_tree
-- Create a hierarchical representation of a vocabulary.
8. taxonomy_node_get_terms
-- Find all terms associated with the given node, ordered by vocabulary and term weight.
Try Using the taxonomy related functions like ,
1. taxonomy_get_children
-- Find all children of a term ID.
2. taxonomy_get_parents
-- Find all parents of a given term ID.
3. taxonomy_get_parents_all
-- Find all ancestors of a given term ID.
4. taxonomy_get_related
-- Find all term objects related to a given term ID.
5. taxonomy_get_term
-- Return the term object matching a term ID.
6. taxonomy_get_term_by_name
-- Try to map a string to an existing term, as for glossary use.
7. taxonomy_get_tree
-- Create a hierarchical representation of a vocabulary.
8. taxonomy_node_get_terms
-- Find all terms associated with the given node, ordered by vocabulary and term weight.
Subscribe to:
Posts (Atom)
Customizing the Search form - Drupal
To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...
-
Query from the DB to retrieve the contents. $query = "SELECT title, link, description, pubDate FROM articles LIMIT 10" ; $re...
-
To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...
-
This module allow you to enable and change following settings in database: - SQL_BIG_SELECTS - MAX_JOIN_SIZE - MAX_ALLOWED_PACKET - WAIT...