Start Cakephp – How to use shell/console/bake

Before Start

This will give an idea to start with cakephp. Here are some details of how to install cakephp, baking a simple application to add, view, edit, delete data with cakephp 1.3.
Continue reading

Posted in PHP, Tutorial | Tagged , | 5 Comments

Jquery simple accordion effect

Before Start

This is a simple jquery accordion effect. While searching for a simple jquery accordion effect, visited this page – Here someone said, “An accordion doesn’t allow more than one content panel to be open at the same time, and it takes a lot of effort to do that….”. Then I saw this simple accordion effect try –, but this will not give a complete accordion effect. But I have got an idea of making a simple accordion effect.
Continue reading

Posted in Jquery, Tutorial | Tagged , , | 10 Comments

Jquery Simple News/Content Ticker

Before Start

This is a simple content display ticker. We can use it for news/quote/testimonial ticker display. Last week I wanted to give a quote ticker in a website. As usual I was looking for Query News Ticker and gone through some. Finally I have decided to make a simple own script, tried and it works fine.
Continue reading

Posted in Jquery, PHP, Tutorial | Tagged , , , , | 16 Comments

Ajax Autocomplete – Part 2 – with name and value

In the previous post Ajax Autocomplete – Jquery PHP Mysql Johnny and Tariq asked how to get the id. With some changes we can store the value in a hidden field.

Please refer the previous post before reading this…
Continue reading

Posted in Ajax, Jquery, PHP, Tutorial | Tagged , , , , , | 106 Comments

Ajax Autocomplete – Jquery PHP Mysql

Before Start

The aim is to design an auto complete script for text box in ajax using Jquery, PHP, Mysql. I have searched for the script, and i have found a simple autocomplete plugin here and you can find the documentation here

You can download the source and see the Demos. But there is no demo fetching data from mysql. Then i have done some small trick in the php file to get data from mysql. This will be very useful in search suggestions, City, State fill up in some registrations.

HTML – Understanding the Layout

Here i have taken course names for example. I have a text box named and ided course. Thats all you need to know in the html layout.

<input type="text" name="course" id="course" />

JS – Include autocomplete plugin and activate

Download the autocomplete source from and get the jquery core, autocomplete javascript file and css file. Include them inside the head tag. After that write some code to activate the text box with autocomplete.

<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
	$("#course").autocomplete("get_course_list.php", {
		width: 260,
		matchContains: true,
		selectFirst: false

To know the autocomplete plugin options go to here and see the Options tab.

PHP – Get data from DB

Get the query word and search within the database and return the list. (get_course_list.php file mentioned in the above javascript)

require_once "config.php";
$q = strtolower($_GET["q"]);
if (!$q) return;

$sql = "select DISTINCT course_name as course_name from course where course_name LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
	$cname = $rs['course_name'];
	echo "$cname\n";

Demo & Download

Download Source

Posted in Ajax, Jquery, PHP, Tutorial | Tagged , , , , , | 199 Comments

PHP – similar did you mean script – Part 1


A year back, i have been searching for the did you mean script on word searching, like in the google search. But, it seemed all were more complicated, and need the complete dictionary database. Then i skip the concept.

Last week, i needed that Did You Mean script for a project, again i did not get a correct script. After a long search, i have decided to go with the PHP function similar_text.

The Idea

It is a word search [DEMO]. There are some courses available in the database, i have to give suggestions if there is any spelling mistake / no result. In this case, we are going to suggest only the existing words in our database, then why going for a complete dictionary? Just we can compare words from the database and give suggestions. For my project, my idea is to show some suggestions if no results found. This helps me instead of Did You Mean script.
Here assume the $keyword is just one word (will come to more than 1 words in part 2)

The script

First understand the PHP function similar_text

Function similar_compare()

function similar_compare($keyword, $course)
	$similar_rate = 0.0;
	$course_words = explode(" ", $course);
	foreach($course_words as $value)
		similar_text(strtoupper($keyword), strtoupper($value), $p);
		if($p > $similar_rate)
			$similar_rate = $p;
	} //foreach
	return $similar_rate;

This function first separate the words in the $course string. Then compare each word with the $keyword and returns the maximum similar rate. Here we use strtoupper, because function similar_text is case sensitive. It is better to change both the words to upper/lower case.

$keyword is the word to be searched in the database. First simply search words using
select * from course where course_name LIKE '%$keyword%'

If there is no result then search for the similar text with the words in the database with every row.

	$sql2 = "select * from course";
	$rsd2 = mysql_query($sql2);
	while($rs2 = mysql_fetch_array($rsd2))
		$course = $rs2['course_name'];
		$rate = similar_compare($keyword, $course);
		if($rate > 70)
			//just displaying the percentage and course name from database
			echo "$rate - $course <br/>";

			//change this according to your requirement - eg: echo '<a href="course details.php?course_id='.$rs2['course_id'].'">'.$course.'</a><br/>';
		} //if
	} //while

Here, we take every row, compare it with keyword using
$rate = similar_compare($keyword, $course);
if the similar rate ($rate) is greater than 70 (change this 70 according to your need) then you can suggest the row (here I am displaying the similar rate and course name)

Feel and Try


Posted in PHP, Tutorial | Tagged , | 14 Comments