Friday 28 December 2012

How to create RSS Feed XML in Core PHP?

Hi Guys,

I am back, after a long time but will continue further...

1. First of All create .htaccess file and write following line into it:
AddType application/x-httpd-php .xml


2. Now,  create an .xml file  and write following code (its an example):


<?php header('Content-type: text/xml'); ?>
<rss version="2.0" >
    <channel>
<title>Panjabilok | Panjabi Culture |  Composite Culture |  Life Style | Saddi Dharti te Log | Sabhyachaar | Faith and Religion | Tourism | Kids &amp; Youth | Science &amp; Technology | Media</title>
<description>Panjabilok | Panjabi Culture |  Composite Culture |  Life Style | Saddi Dharti te Log | Sabhyachaar | Faith and Religion | Tourism | Kids &amp; Youth | Science &amp; Technology | Media</description>
<link><?php echo $_SITE_PATH; ?></link>
<copyright>Copyright 2012. Panjabilok.net All Rights Reserved. Powered by Rubicon </copyright>
<lastBuildDate><?php echo strftime( "%a, %d %b %Y %T %z" , gmdate('Y-m-d H:i:s')); ?></lastBuildDate>


<?php
$query = "SELECT *, UNIX_TIMESTAMP(n_creation) AS pubDate FROM $_NEWS WHERE n_status = '1' ORDER BY n_id DESC LIMIT 10";
$newsResult = $db->query($query);
$data = '';
while($row = $db->fetchArray($newsResult)) { ?>
 
   <item>
        <title><?php echo $row['n_title']; ?></title>
        <description><?php echo $row['short_desc']; ?></description>
        <link><?php echo $_SITE_PATH.'page.php?pg=newsview&amp;n_id='.$row['n_id'].'&amp;c_id='.$row['category_id']; ?></link>
        <guid><?php echo $_SITE_PATH.'page.php?pg=newsview&amp;n_id='.$row['n_id'].'&amp;c_id='.$row['category_id']; ?></guid>
        <pubDate><?php echo strftime( "%a, %d %b %Y %T %z" , $row['pubDate']); ?></pubDate>
   </item>
<?php } $db->freeResult($newsResult); ?>

 </channel>
 </rss>


3. Its done!!!


Your RSS feed has been created.

Cheers!!!



Friday 19 October 2012

How to use commit and rollback transactions using symfony?

Hi All,

$con = Doctrine_Manager::connection();
try {
    $con->beginTransaction();
    // execute all queries...
    $con->commit();
   
}catch (Exception $e) {
   
        $con->rollback();       
        // error message will come here...
   

}

Cheers!

Monday 16 July 2012

How to prevent cut, copy and paste into text field useing jquery?

Hellos,

Please write down following javascript:

<script type="text/javascript">
  $(document).ready(function(){
    $('#textField1').bind("cut copy paste",function(e) {
      e.preventDefault();
    });
   });
</script>

Cheers!

Wednesday 11 July 2012

How to get Relative Path and Absolute path from url_for in symfony?

Hi All,

Suppose you have following url:
http://localhost/archive/web/frontend_dev.php/supportTool/searchByWireTransfer

Now

<?php  echo url_for('supportTool/wireTransferDetails'); ?>
The above code will provide following output:
/archive/web/frontend_dev.php/supportTool/searchByWireTransfer

<?php  echo url_for('supportTool/wireTransferDetails', true); ?>
The above code will provide following output:
http://localhost/archive/web/frontend_dev.php/supportTool/searchByWireTransfer

Cheers!

Friday 25 May 2012

How to check checkbox is checked or not using jquery?

Hi All,

Please use the following code:

How to check checkbox is checked or not using jquery?
function validateMultipleCheck(formId){
    if(formId == undefined){
        var totalInput = $('input:checkbox').length;
    }else{
        var totalInput = $('#'+formId+' input:checkbox').length;
    }
    var checkedValues = '';
    if(totalInput > 0){
        $(":input:checkbox:checked").each(function(){
            checkedValues = checkedValues + ',' + this.value;
        })
    }
    return checkedValues;
}

var values = validateMultipleCheck();
alert(values);


Cheers!

How to check radio button selected or not using jquery?

Folks,

Use the following code:

function validateMultipleRadio(formId){
        if(formId == undefined){
            var totalInput = $('input:radio').length;
        }else{
            var totalInput = $('#'+formId+' input:radio').length;
        }
        var checkedValues = '';
        if(totalInput > 0){
            $(":input:radio:checked").each(function(){
                checkedValues = checkedValues + ',' + this.value;
            })
        }
        return checkedValues;

}

var checkValues = validateMultipleRadio('frm');
alert(checkValues);



Cheers!

Wednesday 23 May 2012

How to fetch data in excel/csv format using mysql query?

Dear All,

Suppose you have a query given below:
SELECT ud.email FROM user_detail ud group by ud.email having count(ud.email) > 1;

The above query return all email addresses which are duplicate in the system.

Now go to server and type following:

## Fetching duplicate email address and saving them into file...   
mysql -uuser_name -p -hhost_name -A -Ddatabase_name -B --skip-column-names -e "SELECT ud.user_id, ud.email FROM user_detail ud group by ud.email having count(ud.email) > 1;">  /var/www/duplicateEmail

"/var/www/" is a path where you want to save file.
"duplicateEmail" is a file name.


Cheers!

Tuesday 15 May 2012

How to implement facebook connect using facebook javascript?

Guys,


######### HTML PART #############
<!---fb:login scope="email" >Login with Facebook</fb:login-->
<input type="button" id="login_button_server" onclick="facebookLogin()" value="Facebook Login"/>
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId: '7845787548501',
            cookie: true,
            xfbml: true,
            oauth: true
        });
        FB.Event.subscribe('auth.statusChange', function(response) {
            //alert(response.status);
            if (response.status === 'connected') {

                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;

                FB.api('/me', function(response) {

                    //alert(response);
                    var email = response.email;
                    var name = response.name;
                    var username = response.username;
                    alert('Good to see you, ' + response.email + '.');
                });
            }else{
                alert("Error found while logged in. Please try again.");
            }
        });

    };
    (function () {       
        var e = document.createElement('script');
        e.async = true;
        e.type = 'text/javascript';
        e.src = 'https://connect.facebook.net/en_US/all.js';       
        document.getElementsByTagName('head')[0].appendChild(e);
    }());


    function facebookLogin() {
        FB.login(function(response) {}, {scope:'email'});
    }
</script>

Cheers!

Friday 4 May 2012

How to install Yii in wamp?

Guys

Follow the following steps for installation:

* goto “My Computer”

* Right Click and select Properties

* You will see “System Properties” window

* Select “Advanced”tab

* In “Advanced” tab, click on “Environment Variables”

* Select “Path” in “System Variables” section

* Click on “Edit”  “Path” in “System Variables” section

* “Edit System Varibale” window will appear with “Variable name” and “Variable value” fields

* Enter “D:\wamp\bin\php\php5 at the end without double quotes.

* Click on OK

* Open dos prompt

* D:\>cd wamp\www

* D:\wamp\www>mkdir myproject

* Download yii framework and put it into www directory

* D:\wamp\www>cd yii\framework

* D:\wamp\www\yii\framework> yiic webapp D:\wamp\www\myproject
Create a Web application under ‘D:\wamp\www\myproject’? [Yes|No] y


Your application has been created successfully under C:\wamp\www\myYii.

Thats all. now You are ready to use your application by accessing the URL : http://localhost/myproject/

Cheers!

Wednesday 25 April 2012

How to find how many processes are running in linux?

Hi Folks,

ps -ef | grep 'ipay4me_new'



here ipay4me_new is a text which is using in process url

Thanks

How to order field by its second character?

Hi All,

SELECT first_name, SUBSTR(first_name, 2) as first_name_sub FROM tbl_passport_application ORDER BY first_name_sub DESC;


Cheers!

How indexing impact on mysql table

############# BEFORE INDEXING ON datetime field ################
Total Records ared: 3299
EXPLAIN SELECT * FROM  `order_request_details` WHERE DATE(  `created_at` ) =  '2012-04-24'
5 Record found out of 3299
id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    order_request_details    ALL    NULL    NULL    NULL    NULL    3372    Using where

EXPLAIN SELECT * FROM  `order_request_details` WHERE  `created_at` =  '2012-04-24'
No result
id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    order_request_details    ALL    NULL    NULL    NULL    NULL    3136    Using where

EXPLAIN SELECT * FROM  `order_request_details` WHERE  `created_at` BETWEEN '2012-04-24' AND '2012-04-24';
No result
id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    order_request_details    ALL    NULL    NULL    NULL    NULL    3533    Using where

EXPLAIN SELECT * FROM  `order_request_details` WHERE  `created_at` >= '2012-04-24:00:00:00' AND  `created_at` <= '2012-04-24:23:23:59';
5 Record found out of 3299
id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    order_request_details    ALL    NULL    NULL    NULL    NULL    3237    Using where


############# AFTER INDEXING ON datetime field ################

EXPLAIN SELECT * FROM  `order_request_details` WHERE DATE(  `created_at` ) =  '2012-04-24'
5 Record found out of 3299
id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    order_request_details    ALL    NULL    NULL    NULL    NULL    3327     Using where


EXPLAIN SELECT * FROM  `order_request_details` WHERE  `created_at` >= '2012-04-24:00:00:00' AND  `created_at` <= '2012-04-24:23:23:59';
5 Record found out of 3299
id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    order_request_details    ALL    NULL    NULL    NULL    NULL    5    Using where

Tuesday 7 February 2012

How to check two dates in javascript?

Hi Folks,

      /* Getting current year */
    var current_date = new Date();
      /* Converting user input date of birth to javascript data format... */
      var date_of_birth = new Date($('#order_date_of_birth_year').val(),$('#order_date_of_birth_month').val()-1,$('#order_date_of_birth_day').val());
      if(date_of_birth.getTime()>current_date.getTime()) {
        $('#date_of_birth_error').html("Date of Birth cannot be a future date");
        err = err+1;
        return false;
      }else {
          $('#date_of_birth_error').html(" ");
      }

Cheers!

Friday 13 January 2012

How to delete files periodically usign cron.

Hi All,

Please use the following line to delete files:

find /var/www/archive/dbbackup/ -type f -name '*.sql.gz' -mtime +1 -exec rm {} \;

-mtime +1 means all files older more then 1 day.

Thanks
Cheers!