Social Icons

Wednesday, September 18, 2013

Unsupported template dependency: Upgrade your android eclipse plugin

Once I was working on creating an android application and while configuring, I got this error as "Unsupported template dependency: Upgrade your android eclipse plugin". Below it was written as :
Required version: (empty)
Installed Version: 18

Here, I got the fix for this issue.
Suppose if you selected for Blank Activity then you have to make one change as follows:
Go to sdk/tools/templates/activities/BlankActivity/template.xml
and comment out the dependency tag as follows:
<!--<dependency name="appcompat" version="v7" />-->

Thats it. You are done. Restart eclipse and try to create again. This fixed my issue.

Similarly, if you selected for MasterDetailFlow then
Go to sdk/tools/templates/activities/MasterDetailFlow/template.xml and comment the line
<!--<dependency name="support" version="v4" />
<dependency name="android-support-v4" revision="8"/>-->

Thats it. Above steps should fix your issue of unsupported template dependency.

Tuesday, August 27, 2013

Difference between two dates in php

Here, I am going to tell you the solution for if you have to find out the difference between two dates in php. Suppose, you have two dates and you want the interval difference between them in terms of year, month, day, hours, minutes and seconds then you can do it as follows:

<?php
$old_date = '2012-08-26';
$cur_date = date("Y-m-d H:i:s"); //This will give you current date and time

$old_date = new DateTime($old_date);
$cur_date = new DateTime($cur_date);

$interval = $cur_date->diff($old_date);
$year     = $interval->y; //Outputs year difference
$month  = $interval->m; //Outputs month difference
$day      = $interval->d; //Outputs days difference
?>

From the above code, you can easily get the date difference between two dates.

Wednesday, July 17, 2013

How to make a free website

A very common question, how to make a website. Here, I am going to explain this in detail.

Most of the people want to create their own website. Specially they want it for free completely means they want to create a website for completely free of cost. So, how to make a free website???. Well, a website is of two types: Static websites and dynamic websites. A static website is that which content is fixed for all users while dynamic website's content differ from user to user for example: your home page content of facebook is different from your friend.

A website can be designed in two ways: either using website builder (or something like cms) or with programming. In this part, I will explain how to create a free website without having knowledge of programming. In the later part, I will discuss to create website with programming and publish it. So, if you don't know programming and want to create a website for free, then this part is for you. Here we go.

You can create website with site builders. There are so many site builders available on internet. They are: weebly (www.weebly.com), wix (www.wix.com), google sites (sites.google.com) etc. They all have features like having a lot of templates, drag and drop features for paragraph, title, images etc. With the free edition, they may provide you lesser facilities. By upgrading your account on some payment, you will get more features there. That you can decide after checking out the features there and as per your needs. Also, you will get one click publish there which will publish your website on internet and anyone can see it.

Do registration in any of the above mentioned websites and there you will get option to create a free website. You will type name for your website like what you want to keep name of your website (for example www.prembaranwal.com) But you will get an option to have your website name as a sub-domain name only. For example, if you are creating your website through weebly, then your website will be like this www.yourwebsite.weebly.com like that. These site builders have some pattern for your website link(url) generation. If you want to make it with your domain name only (like www.yourwebsite.com) then you have to pay for it and upgrade your account. In that case, they will set up your account with your desired domain name and your website will open with www.yourwebsite.com A website always looks more professional with your own website domain name. But if you don't want to pay anything then also its ok. You can publish your website with subdomain as I mentioned above and anyone in the world can see it.

In the next tutorial, I will explain: If you know programming and have made the website in your local and want to publish on the web (internet) for free or at a minimal charge

Monday, June 24, 2013

Check mysql engine for a specific table

In MySql, there are many storage engines like MyISAM, InnoDB etc. What if you want to check the type of storage engine for a specific table as what storage engine it is using. You can check it as follows:

Run the below query:

SHOW TABLE STATUS WHERE Name='your_table_name'

The above query will give you the storage engine name with some more additional data, your table uses.

Similarly, if you want to check storage engines for all tables in your mysql database at once, then simply run this query:

SHOW TABLE STATUS

It will give you details about the storage engines for all the tables in your mysql database.

Wednesday, June 19, 2013

PHP file upload

In a website, it is a common requirement to upload a file or photo (image). Here, I am providing a solution as how can do it in PHP. It is not advisable to store the file in database directly. Instead, you should store the file in your project folder and in your database, you should store only the path of the file. So, we'll follow the same approach only.

First we design a form containing a file field. HTML code for the form containing a file field is :

<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
File: <input type="file" name="myfile" id="myfile"/>
<br/>
<input type="submit" name="submit" id="submit" value="Upload File"/>
</form>
</body>
</html>

Above is just the html code for displaying a file field in the web page. Now, on clicking  of submit button, it will redirect you to upload.php as it is defined in form action. So, we'll write the code for upload.php now.

upload.php

<?php

if ( $_FILES['myfile']['error'] > 0)
{
  echo "Error: ".$_FILES['myfile']['error'];
}
else
{
  if (file_exists("upload/" . $_FILES["myfile"]["name"]))          //upload/file is the path where file                                                                                                                 gets stored
  {
      echo $_FILES["myfile"]["name"] . " already exists. ";
  }
  else
  {
      move_uploaded_file($_FILES["myfile"]["tmp_name"],
      "upload/" . $_FILES["myfile"]["name"]);
      echo "File Stored in: " . "upload/" . $_FILES["myfile"]["name"];
   }}
?>


Thats it. Now, your file upload script is ready. In the above code, "upload/" . $_FILES["myfile"]["name"] is the path where file gets uploaded or stored.  Make sure, you have 'upload' directory in your project folder path. Now as your file gets stored, if you want to save its path in database, then you can run a sql query in your upload.php script as its path after uploading the file. In that case, anytime you can echo the file with the help of the path.

Thursday, June 6, 2013

Find 2nd highest or nth highest salary of employee in sql

It is one of the common questions for developers and also asked in interviews frequently to find 2nd highest salary or nth highest salary of an employee from the employee table. Here, I am providing solution for both.

To find 2nd highest (or maximum) salary of employee, you can write your query like this in MySql:

Select max(salary) as salary 
From employees 
Where salary<(Select max(salary) From employees);

The above sql query will give you the 2nd highest salary of employee. Here, 'employees' is the name of the table in the database.

But, what if you have to find 3rd highest or 4th highest or nth highest salary of employee. If you will follow the above approach then you will have to write the subquery for n times. That doesn't seem good. Here, I am providing a generalized solution to find nth highest salary.  Look at the below sql query:


SELECT DISTINCT(salary) 
FROM employees 
ORDER BY salary DESC LIMIT (n-1) , 1


Here, n is the highest term for which you have to find out highest salary. The above query will give you nth highest salary.

Tuesday, June 4, 2013

Difference between single quote and double quote in PHP

In PHP, if yu have to display or echo something (say a string), then you can do it with the help of single quote and double quote both. But there is a little difference between them as :

A single quoted string doesn't have variables within it interpreted but a double quoted string does. It can be better understood with the following example:

<?php
$a = 'prem';
echo 'My name is $a';
echo "My name is $a";
?>

For the first echo statement having single quote, output will be
My name is $a

For the second echo statement having double quoted string, output will be
My name is prem

So, if you have to define a constant string then better use with single quote and if you have variable too in the string then go with double quotes.

Total Pageviews