Latest Entries »

Using javascript we can easily find the height and width of an image.
Now using the following javascript we can determine the height and width

var myimage = document.getElementById("myimage");
var w = myimage.width;
var h = myimage.height;

Detect if ENTER key is pressed in Jquery

    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13'){
        alert('You pressed a "enter" key in somewhere');   

Select data’s 4 days older than current date against unix timestamp field in where clause mysql

We can use the PHP function file_get_contents() to get the image from the remote server.

$remoteimage = “”;
$localimage = “/home/domain/httpdocs/path/to/my/image.jpg”;
if ($content = file_get_contents($remoteimage)) {
if (!empty($content)) {
$fp = fopen($localimage, “w”);
fwrite($fp, $content);

Using the mysql_list_fields function we can get the mysql fields and with that we can find a field exist in a table or not. Check the code below,


$tableFields = mysql_list_fields("databasename", "tablename");
$columns = mysql_num_fields($fields);

for ($i = 0; $i < $columns; $i++) {
$field_array[] = mysql_field_name($fields, $i);

if (!in_array(‘list_id’, $field_array)) {
mysql_query("ALTER TABLE `tablename` ADD `fieldname` INT(11) NOT NULL DEFAULT ’1′;");


Set SEO url in wordpress

As we can see, by default wordpress url looks/works based on post id. If we want to set a seo url for posts. We can do it by editing wordpress settings.

  • Login as adminitrator.
  • Click on the settings menu and permalinks.
  • WordPress has many url formation settings over there as an added feature. And if you want to set the url using the post name with its cateogory. Click on the “Custom Structure”.
  • In the space provided just type as follows,


  • Click on save changes and check your site now. We have formed a seo url for posts.
  • Also if you want add extension like “html”,”php”,etc. You can do it like,



Multiple file upload in php

Add “multiple” attribute in the html “file” tag to upload multiple files in single click,
<input type="file" multiple />
For loading ajax and changing the url without refreshing the page, use pushState as the location.hash function no more exists.
For more on pushState, check the link below,


Reduce the code of

Wrong code

<a href=”#” > <input type=”button” value=”Home” /> </a>

<a href=”#” > <input type=”submit” value=”Home” /> </a>



<a href=”#” title=”Link” > Home </a>

Wrong code

<a href=”#”><div>HAI</div></a>  


<div><a href=”#” title=”Link”>HAI</a></div>

Wrong code

<span><div>HAI HOW ARE U</div></span>


<span> HAI HOW ARE U</span>

Say for example, In my mysql table one of the field has values like (1|2|3) stored in it.

 id   Skills
 ----  --------
   1   1|2|3|5
   2     2|4|5
   3    4|6|3
   4    5|2|3|1

I want to search and list the id’s based on the skills matched. If i want to list the id’s of the skill which contains 3, i have to list the ids 1,3,4. Like if i want to list the id’s of the skill which contains 1,5 (either 1 nor 5 or both)(like mulitple values 1,4,3) then i want to list 1,2,4(i want to list 2 also).

For this we have a very useful mysql function FIND_IN_SET(), Check the below query,


select id
from your_table
where find_in_set('3', replace(skills, '|',',')) > 0
or find_in_set('5', replace(skills, '|',',')) > 0


How to set cron job

The following format will explain the cron job functionality in detail.

Minutes [0-59]  
|   Hours [0-23]  
|   |   Days [1-31]  
|   |   |   Months [1-12]  
|   |   |   |   Days of the Week [Numeric, 0-6]  
|   |   |   |   |  
*   *   *   *   * home/path/to/command/  

 59 23 * * * home/path/to/command/