Friday 7 December 2012

Auto complete text box with PHP, jQuery and MySql

In this tutorial I want to show you how easy to do a auto complete text box with PHP, jQuery and MySql.

Firstly download the autocomplete jQuery plugin and extract it to your hard drive.
And then create a folder in your localhost. Copy jquery.autocomplete.css and jquery.autocomplete.js file to your project folder. And you will also need jquery.js. Now we can start our project. 

Creating database table


We need to create a table in our database before writing our script. I also add some data for this table. Import following SQL statement via phpMyAdmin or any other MySQL tool.

CREATE TABLE `tag` (
  `id` int(20) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

INSERT INTO `tag` (`id`, `name`) VALUES
(1, 'php'),
(2, 'php frameword'),
(3, 'php tutorial'),
(4, 'jquery'),
(5, 'ajax'),
(6, 'mysql'),
(7, 'wordpress'),
(8, 'wordpress theme'),
(9, 'xml');

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto Complete Input box</title>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<script>
 $(document).ready(function(){
  $("#tag").autocomplete("autocomplete.php", {
        selectFirst: true
  });
 });
</script>
</head>
<body>
<label>Tag:</label>
<input name="tag" type="text" id="tag" size="20"/>
</body>
</html>

autocomplete.php

This file is called from our jquery script. This php script is easy to follow.
<?php
 $q=$_GET['q'];
 $my_data=mysql_real_escape_string($q);
 $mysqli=mysqli_connect('localhost','username','password','databasename') or die("Database Error");
 $sql="SELECT name FROM tag WHERE name LIKE '%$my_data%' ORDER BY name";
 $result = mysqli_query($mysqli,$sql) or die(mysqli_error());

 if($result)
 {
  while($row=mysqli_fetch_array($result))
  {
   echo $row['name']."\n";
  }
 }
?>
We have done. Run your project and type in your text box you will see following screenshot. 

By the way, I use the old jquery plug in this project. If you want to learn new thing, you can learn hereand here. I create this tutorial because it is still useful and easy, although it is too old. I will also write about new jquery ui later.
Download Source Code

Thanks To :  Wai Lynn Oo

Thursday 29 November 2012

10 Most Wanted Google Search Tips and Tricks

Hi Guys,


For 2 Days I had fight with Google search engine ("A friendly Fight")  and a play with keywords. Here are some tips I played to make my search as quick as possible.

1.Use – (minus) before the search
eg: Google Chrome -free

2. Search for Keywords with Similar Meaning
eg: for troubleshoot use clean, Repair, make ready...like

3. Search Using *
eg:  C Language by Author *

4. Use OR
eg: buy iPhone OR Samsung galaxy s3
Note: OR should be in Caps

5.Define or Wiki
For Definition use like below
eg: Define: Xcode or Wiki: Xcode

6. Range Using '..'
eg: Buy Iphone 5 $350..$550

7. Search within a site
eg: installation site:http://windows.microsoft.com
Note: Dont Leave space between Site: and website name

8.Search Based on File Type
eg: Android :pdf

9. Use Advanced Search
Google Advanced Search Page

10. use usual Keywords
 eg: weather, time, Mathematical calculations and functions directly
Money conversion and stock is so accurate.

Hope it is so helpful...Comment me.....Bye....

Tuesday 27 November 2012

Mobile Website Redirect

Hi Guys,

Today is about - "Mobile" - 

If you've created a mobile version of your website, you'll need to be sure that you redirect your mobile visitors to your mobile website.For example, if someone visits domain.com on their phone, you'll need a way to redirect them to m.domain.com (the mobile version of your site).

If you are running a Content Management System (such as WordPress or Joomla), there may be plugins already available that help with handling mobile visitors.



Javascript Method

Because mobile phones typically have a small screen width, you can redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels. You can use the following code to do this:

<script type="text/javascript">
 <!--
 if (screen.width <= 800) {
  window.location = "http://m.domain.com";
 }
 //-->
</script>

Note:
Please keep in mind however that if the user does not have javascript enabled, this will not work.



.htaccess redirects

You can use a .htaccess redirect to transfer visitors based upon mime types that their browser accepts. For example, if the user's browser accepts mime types that include WML (Wireless Markup Language), then most likely it is a mobile device.
The code below should be placed in your .htaccess file:
RewriteEngine On
# Check for mime types commonly accepted by mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]


Like this Article?





MySQL - Add seconds to datetime

Hi Guys,
Here is my first blog about Tech Talks.

MySQL
When I like to add 10 seconds to n existing datetine field inside a table, i couldnot made it. I tried several Methods and functions like ADDDATE(),DATE_ADD(),DATEADD(),TIME,etc. After spending an hour I got it.Here it goes!

Select DATE_ADD('date-with-time-goes-here', INTERVAL '00.10' MINUTE_SECOND)

I made it.