Saturday, March 9, 2013

Password Generator and Random Number String Function


We want to Random Number String & Password Generator Function using any technology ( like php, jsp, asp, java)


Random Number String generator function

function r($len){
$keyset = “abcdefghijklmnopqrstuvwxyz0123456789?;
$randkey = “”;
for ($i=0; $i<$len; $i++)
{
$randkey = $randkey . $keyset[mt_rand(0, strlen($keyset)-1)];
}
return $randkey;
}

Strong Password generator function

function generatePassword($length=9, $strength=0) {
$vowels = ‘aeuy’;
$consonants = ‘bdghjmnpqrstvz’;
if ($strength & 1) {
$consonants .= ‘BDGHJLMNPQRSTVWXZ’;
}
if ($strength & 2) {
$vowels .= “AEUY”;
}
if ($strength & 4) {
$consonants .= ’23456789';
}
if ($strength & 8) {
$consonants .= ‘@#$%’;
}

$password = ”;
$alt = time() % 2;
for ($i = 0; $i < $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}



Calculating Age using MySQL

We want to  Calculating Age Current date from Date of Birth in MySQL.Following Given many option find out  age.



SELECT NOW()  - Returns the current date and time
Output- 2013-03-09 14:16:44
SELECT CURDATE()  - Returns the current date
Output- 2013-03-09


1. SELECT DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT('1981-10-25', '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT('1981-10-25', '00-%m-%d'))
AS age
output- 31

2. SELECT YEAR(DATE_SUB(NOW(), INTERVAL TO_DAYS('1981-10-25') DAY)) AS age
output- 31

3. SELECT ROUND(DATEDIFF(CURDATE(),'1981-10-25')/365) AS age 
output- 31

MySQL Date Functions

DATE_SUB() - The DATE_SUB() function subtracts a specified time interval from a date.
CURTIME() - Returns the current time
DATE() - Extracts the date part of a date or date/time expression
EXTRACT() -Returns a single part of a date/time
DATE_ADD()- Adds a specified time interval to a date
DATEDIFF()- Returns the number of days between two dates
DATE_FORMAT()- Displays date/time data in different formats
TO_DAYS() - Return the date argument converted to days

More function see it

Thursday, March 7, 2013

Sorting Alphanumeric using mysql query


Several times ,I have need to sort alphanumeric rows in a database by number (i.e. emp1, emp2, emp3,emp10,emp15 etc.) in Project .  you  want to sorting alphanumeric using mysql query. Follwing code use.



The Data
For our purposes, we’ll be using the following table:

Table: sorting_image
 -------------------------- -------------
| alphanumeric VARCHAR(77) | idnumber INT |
 -------------------------- -------------
| image1                    | 1           |
| image2                    | 2           |
| image3                    | 3           |
| image4                    | 4           |
| image5                    | 5           |
| image6                    | 6           |
| image7                    | 7           |
| image8                    | 8           |
| image9                    | 9           |
| image10                   | 10          |
| image11                   | 11          |
| image12                   | 12          |
 -------------------------- -------------

 Sorting by the column idnumber, 



 Query: SELECT alphanumeric, idnumber
       FROM sorting_image
       ORDER BY idnumber
 -------------------------- -------------
| alphanumeric VARCHAR(77) | idnumber INT |
 -------------------------- -------------
| image1                    | 1           |
| image2                    | 2           |
| image3                    | 3           |
| image4                    | 4           |
| image5                    | 5           |
| image6                    | 6           |
| image7                    | 7           |
| image8                    | 8           |
| image9                    | 9           |
| image10                   | 10          |
| image11                   | 11          |
| image12                   | 12          |
 -------------------------- -------------

if you sorting by the alphanumeric column, we get unexpected results:

 Query: SELECT alphanumeric, idnumber
       FROM sorting_image
       ORDER BY alphanumeric
 -------------------------- -------------
| alphanumeric VARCHAR(77) | idnumber INT |
 -------------------------- -------------
| image1                    | 1           |
| image10                   | 10          |
| image11                   | 11          |
| image12                   | 12          |
| image2                    | 2           |
| image3                    | 3           |
| image4                    | 4           |
| image5                    | 5           |
| image6                    | 6           |
| image7                    | 7           |
| image8                    | 8           |
| image9                    | 9           |
 -------------------------- -------------

 Solution

 Obviously, desired Results not come. Since we’re sorting alphabetically, the entries are actually in the correct order, but we need to find a way to sort numerically as called Natural Sorting . Please use  in mysql query "sort by length"  column value.


 Query: SELECT alphanumeric, idnumber
       FROM sorting_image
       ORDER BY LENGTH(alphanumeric), alphanumeric
 -------------------------- -------------
| alphanumeric VARCHAR(77) | idnumber INT |
 -------------------------- -------------
| image1                    | 1           |
| image2                    | 2           |
| image3                    | 3           |
| image4                    | 4           |
| image5                    | 5           |
| image6                    | 6           |
| image7                    | 7           |
| image8                    | 8           |
| image9                    | 9           |
| image10                   | 10          |
| image11                   | 11          |
| image12                   | 12          |
 -------------------------- -------------


Wednesday, March 6, 2013

Find out Name and Domain name in email column of table database


   Email Extract


We have find out Name  in email id  of table database. Find below query find name in email id.

Name of email id
select SUBSTR(email, 1, (INSTR(email, '@')-1)) as name from emails

Domain name of email id
select SUBSTR(email, INSTR(email, '@')+1) as name from emails

Tuesday, March 5, 2013

Made multi color Button using css

We have Made multicolor  Button using css in webpage. Following css and html code   use.

Css Code

.buttonnewlink{height:auto; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px; border-radius:5px;  padding:8px;*padding:5px; display:inline; overflow:hidden; background-image:-moz-linear-gradient(0% 22px 90deg, #de9e0a, #9f2222); background-image:-webkit-gradient(linear, 0% 0%, 0% 70%, from(#de9e0a), to(#9f2222)); background-color:#de9e0a; float:right; margin:-20px 27px 0 0px;}
.buttonnewlink a{font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; font-size:16px; color:#fff; font-weight:bold; text-decoration:none;}
.buttonnewlink a:hover{text-decoration:none; color:black;}

HTML code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<div class="buttonnewlink"><a href="#">Booking Now</a></div>
</BODY>
</HTML>

Output



headers already sent Error session

          We   get  error / Warning headers already sent in  session using php Programming. Following code    solution you solve problem


Warning: session_start(): Cannot send session cookie - headers already sent

Step one :- Search & Open PHI.INI


Step Two:- Search session.cache_limiter 



Step three:- put " public " in front of session.cache_limiter 

Set Value

session.cache_limiter =public


Monday, March 4, 2013

Customize Generate url using htaccess




Please Use below code rewrite url using Htaccess


# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
RewriteEngine On

# main list

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

RewriteRule ^index/.html$ index.php [L,QSA]
</IfModule>
//////////////////////////////

Also Redirect module enable in httpd.conf
"Below line  Remove # (By Default )"
'#LoadModule rewrite_module modules/mod_rewrite.so'
After That
'LoadModule rewrite_module modules/mod_rewrite.so'

save file restart wamp server