Tuesday, March 27, 2012

Remove or Delete duplicate records in a table in MySQL

Remove the duplicate records in a table, it will delete records which is having greater than the sno

For example: table name: players

snonamecoach_id
1Sachin1
2Sachin5
3Kohli1
4Ganguly2
5Kohli4
6Gambir3

Query:
DELETE FROM players USING players , players AS virtualtable
WHERE players .sno > virtualtable.sno
AND players .name = virtualtable.name

Output:
snonamecoach_id
1Sachin1
3Kohli1
4Ganguly2
6Gambir3

Display limited records with out using LIMIT in MySQL

If you want to get display limited records with out using LIMIT option in MySQL.
For example: table name: players

snonamecoach_id
1Sachin1
2Dravid5
3Kohli1
4Ganguly2
5Sehwag4
6Gambir3

Query:
SELECT one.sno, one.name FROM players AS one
WHERE ( SELECT COUNT(*) FROM players AS two WHERE two.sno <= one.sno ) <= 3

Output:
snonamecoach_id
1Sachin1
2Dravid5
3Kohli1




Get data condition related information from a single table

If you want to display the data with condition based from a single table.

For example: table name: players

snonamecoach_id
1Sachin1
2Dravid5
3Kohli1
4Ganguly2
5Sehwag4
6Gambir3

Query:
SELECT player.sno, player.name, coach.name AS coachname
FROM players AS coach
JOIN players AS player ON coach.sno = player.coach_id

Output:
snonamecoach_id
1SachinSachin
2DravidSehwag
3KohliSachin
4GangulyDravid
5SehwagGanguly
6GambirKohli

Thursday, March 8, 2012

Facebook and Drupal 6 Implementation

Drupal for Facebook

1.Download Drupal for Facebook Module. And place into sites/all/modules folder.
2.Download Facebook-PHP-SDK library and place into sites/all/libraries folder. Folder should be facebook-php-sdk.
3.In settings.php files, you have to add the following lines,
1.include "sites/all/modules/fb/fb_url_rewrite.inc";
2.include "sites/all/modules/fb/fb_settings.inc";
3.$conf['fb_api_file'] = 'sites/all/libraries/facebook-php-sdk/src/facebook.php';

4.Then enable the following module
1.fb.module
2.fb_app.module
3.fb_connect.module
4.fb_user.module

5.Goto admin/reports/status page and verify the Facebook PHP SDK loaded or not.

6.Then you have to generate the API/Secret key in facebook for your site.
1.App Display Name - Your application display name – Human readable without space
2.App Namespace: Your namespace of your domain (All letters are small)
3.Contact Email – Your Email id
4.Category – Other
5.Website – Site URL – http://www.domain/com

7.Go to admin/build/fb page and configure the Application for Facebook API settings.

8.You have add the following attribute in your html tag: xmlns:fb="http://www.facebook.com/2008/fbml"

Login Button Interface
=================


Manual
---------
$_fb_app = fb_invoke(FB_OP_CURRENT_APP);
$facebook = new Facebook(array(
'appId' => $_fb_app->apikey,
'secret' => $_fb_app->secret,
'cookie' => true,
));
$loginUrl = $facebook->getLoginUrl();

global $base_url;
$params = array( 'next' => $base_url . '/' ); // Custom redirection after logout link press
$logoutUrl = $facebook->getLogoutUrl($params);
?>

Or Drupal Theme

print theme('fb_login_button', t('Connect with Facebook'), array('attributes' => array('size' => 'large', 'background' => 'dark', 'onclick' => 'removePopup();')));

Or FML Tag

<fb:login-button>Connect with Facebook < /fb:login-button>

Or Javascript

<a href=”javascript: doLogin();” > Connect with Facebook < /a>

JS:
doLogin();

function doLogin() {
FB.login(function(response) {
if (response.session) {
FB.api('/me', function(response) {
//alert('User: ' + response.name);
//alert('Full details: ' + JSON.stringify(response));
}
);
}
} , {perms:''});
}


Required Versions:
==============

Drupal 6.x
DFF - 6.x-3.0-beta1
facebook-php-sdk - Facebook PHP SDK (v.3.1.1)

Issues in DFF and Drupal
===================

Whereever they using getSession() function inside fb module folder, we have to repalce getUser() function. Because getSession() is not exist in Facebook PHP SDK kit.

Tuesday, October 4, 2011

List out some hook function in drupal

hook_access->Define access restrictions.
hook_auth->Verify authentication of a user.
hook_block->Declare a block or set of blocks.
hook_comment ->Act on comments.
hook_cron->Perform periodic actions.
hook_db_rewrite_sql ->Add JOIN and WHERE statements to queries and decide whether the primary_field shall be made DISTINCT. For node objects, primary field is always called nid. For taxonomy terms, it is tid and for vocabularies it is vid. For comments, it is cid. Primary...
hook_delete->Respond to node deletion.
hook_elements->Allows modules to declare their own form element types and specify their default values.
hook_exit->Perform cleanup tasks.
hook_file_download ->Allow file downloads.
hook_filter->Define content filters.
hook_filter_tips->Provide tips for using filters.
hook_footer->Insert closing HTML.
hook_form->Display a node editing form.
hook_form_alter->Perform alterations before a form is rendered. One popular use of this hook is to add form elements to the node form.
hook_help->Provide online user help.
hook_info->Declare authentication scheme information.
hook_init->Perform setup tasks.
hook_insert->Respond to node insertion.
hook_install->Install the current version of the database schema.
hook_link->Define internal Drupal links.
hook_load->Load node-type-specific information.
hook_menu->Define menu items and page callbacks.
hook_nodeapi ->Act on nodes defined by other modules.
hook_node_grants->Grant access to nodes.
hook_node_info->Define the human-readable name of a node type.
hook_perm->Define user permissions.
hook_ping->Ping another server.
hook_prepare ->This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
hook_search->Define a custom search routine.
hook_search_preprocess->Preprocess text for the search index.
hook_settings->Declare administrative settings for a module.
hook_submit->This is a hook used by node modules. It is called after validation has succeeded and before insert/update. It is used to for actions which must happen only if the node is to be saved. Usually, $node is changed in some way and then the actual saving of...
hook_taxonomy->Act on taxonomy changes.
hook_update->Respond to node updating.
hook_update_index->Update Drupal's full-text index for this module.
hook_update_N->Perform a single update. For each patch which requires a database change add a new hook_update_N() which will be called by update.php.
hook_user->Act on user account actions.
hook_validate ->Verify a node editing form.
hook_view->Display a node.
hook_xmlrpc->Register XML-RPC callbacks.
module_hook->Determine whether a module implements a hook.
module_implements->Determine which modules are implementing a hook.
module_invoke->Invoke a hook in a particular module.
module_invoke_all->Invoke a hook in all enabled modules that implement it.