Sunday 14 September 2014

Find Last Message FROM All Users


 Query to find out the last message from all users in conversation

select messages.message_text, messages.sender_uuid, messages.receiver_uuid, messages.add_date  FROM messages 
INNER JOIN (
SELECT  MAX(add_date) AS time, IF(`receiver_uuid` = '1',  `sender_uuid`, `receiver_uuid`) AS user FROM     dp_messages GROUP BY user) m2 
ON messages .add_date = m2.time 
AND (messages .`sender_uuid` = m2.user  OR dp_messages .`receiver_uuid` = m2.user)
WHERE 

`sender_uuid` = '1' OR `receiver_uuid` = '1' 
ORDER BY messages .add_date DESC LIMIT 0, 20

Tuesday 9 September 2014

Mysql, Query to find out table comments?

To List all tables from database use: 

show tables from DatabaseName;


To List Table Structure you can use: 

DESC tablename;
Or You can use
SHOW COLUMNS FROM file FROM DatabaseName;

Query to find out Comments on Table

SELECT a.COLUMN_NAME, a.COLUMN_COMMENT FROM information_schema.COLUMNS a WHERE a.TABLE_NAME = 'YOUR_TABLE_NAME'

Just Change the name of YOUR_TABLE_NAME and run it.

Monday 21 July 2014

Export Data From Server Using Terminal

To Export Data from Terminal Use Following Command :


mysql -p -u databasename > databasename.sql 
OR
mysqldump -p -u databasename > databasename.sql




To Import Data from Terminal Use Following Command :

mysql -p -u databasename < databasename.sql

OR
mysqldump -p -u databasename > databasename.sql

Copy Data from server to localhost using ssh



 First Of all compress the file using following command

tar -cf name.tar name_of_folder

To copy a compressed folder from the server use following command

scp user@remotehost.com:/filepath/file.txt /some/localhost/folder

scp user@remotehost.com:/var/html/project.tar /var/www/



Keep Exploring

Friday 27 June 2014

Get Mysql Query Count

This Query will return the count of queries fired in database

 
mysqladmin ext | grep -e 'Com_\(update\|select\|insert\)'

Wednesday 14 May 2014

Php: Generate Captcha Secure Image

global $image;
    $_SESSION['count'] = time();
   
    $image              = imagecreatetruecolor(200, 50) or die("Cannot Initialize new GD image stream");
    $background_color   = imagecolorallocate($image, 255, 255, 255);
    $text_color         = imagecolorallocate($image, 0, 255, 255);
    $line_color         = imagecolorallocate($image, 64, 64, 64);
    $pixel_color        = imagecolorallocate($image, 0, 0, 255);

    imagefilledrectangle($image, 0, 0, 200, 50, $background_color);

    for ($i = 0; $i < 3; $i++) {
        imageline($image, 0, rand() % 50, 200, rand() % 50, $line_color);
    }

    for ($i = 0; $i < 1000; $i++) {
        imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color);
    }


    $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $len = strlen($letters);
    $letter = $letters[rand(0, $len - 1)];

    $text_color = imagecolorallocate($image, 0, 0, 0);
    $word = "";
    for ($i = 0; $i < 6; $i++) {
        $letter = $letters[rand(0, $len - 1)];
        imagestring($image, 7, 5 + ($i * 30), 20, $letter, $text_color);
        $word .= $letter;
    }
    $_SESSION['captcha_string'] = $word;

    $images = glob("*.png");
    foreach ($images as $image_to_delete) {
        @unlink($image_to_delete);
    }
   
    imagepng($image, "image" . $_SESSION['count'] . ".png");


To display The captcha

<img src="../image<?php echo $_SESSION['count'] ?>.png">



Tuesday 6 May 2014

Cakephp: Insert Query In Loop

If You are Using $this->Model->save() in  LOOP then this will not work.
TO overcome this issue simply add

Add this before save this will move the cursor to a new Line and then insert again.

$this->Model->create()
$this->Model->save()

Monday 5 May 2014

Cakephp: Debugging Query in Cakephp

$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);

Tuesday 29 April 2014

CakePhp Get Complete path

You can Have a Complete Path in cakephp using

<?php echo Router::url( $this->here, true ); ?>

If you want a relative path to be shown Use this :

<?php echo  $this->here; ?>

Wednesday 16 April 2014

Technology Next Generation

Amazing New Technology that are beyond what 

we think


Keep Exploring !!

Thursday 10 April 2014

Drupal: How to show and Hide form fields on form option select

Drupal Offer a great platform. You do not need to include any javascript or ajax to do so. What all you need to add in your form fields is

            '#states' => array('visible' => array(':input[name="report_for"]' => array('value' => '3'),),),

and all set


Create your select option attribute

$options = array('1' => 'Option1', '2' => 'Option2', '3' => 'Option3');

   $form['field_name'] = array(
            '#title' => t('Field Title'),
            '#type' => 'select',
            '#options' => $options,
            '#empty_option' => NULL,
            '#empty_value' => NULL,
            '#default_value' => 1,
            '#required' => TRUE,
  );

And field that you want to he shown on selection any option in that fields simply right like this

        $form['field_name'] = array(
            '#title' => 'Field Title',
            '#required' => TRUE,
            '#states' => array('visible' => array(':input[name="report_for"]' => array('value' => '3'),),),
        );

Now this field is visible only when a user select option3.


Saturday 5 April 2014

Bloggers: How to redirect bloggers to your own domian

When You Think That you have enough traffic on your blog now you want to go on with more ideas and for better future o blog, IF you want to go live with the custom domain name, you can redirect bloggers account to your custom domain without loosing your Traffic. What all you need to do is copy and paste following given script.

Steps to be Followed 

  • Login to your bloggers account.
  • Click on Template Menu .
  • Paste the below given script on your template file.

To Redirect all pages from of bloggers to your custom domain Home Page Paste the Following script in your <head> section of a Template.

<script type='text/javascript'>
      var d='<data:blog.url/>';
      d=d.replace(/.*\/\/[^\/]*/, '');
      location.href = 'http://domain.com/';
</script>


Keep Exploring!!

Friday 4 April 2014

Wordpress : Best way to show Twitter Feeds

To show Twittwer Feeds without using Plugin

What all you need to do

Go to Appearence -> widget

Drag and drop Text Widget

Paste the following code in a Text Area

<a class="twitter-timeline"  href="https://twitter.com/screenname"  data-widget-id="309736537778683904" data-screen-name="screenname" data-list-owner-screen-name="screenname_app" data-chrome="noheader nofooter noborders transparent noscrollbar">Tweets by @screenname</a>

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

Thursday 3 April 2014

Php: Remove Admin Bar In Wodpress

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}

Wednesday 2 April 2014

Php : Get Time in a milisec

 This will result the time in a milisec :

$mileSec = round(microtime(true) * 1000);