Pulkit Gaur

dream - do - deserve

MYSQL Clone records in same table

Filed under: PHP at 05:03:33 On 2007-05-09

While working on picporta we had one requirement where were supposed to clone records within the same table.

Searching in MYSQL manual i found INSERT-SELECT statement but it still does not supports same table Undecided


So did this quick hack in PHP ..


$tempTable = mysql_fetch_array(mysql_query("SELECT * FROM table." WHERE id='$passedId'),MYSQL_ASSOC) or die("Could not select record");
$result = mysql_query("INSERT INTO table (".implode(", ",array_keys($tempTable)).") VALUES ('".implode("', '",array_values($tempTable))."')");



Worked for me ..

Google Suggest - Hack

Filed under: PHP at 04:00:00 On 2006-05-09

You may like to visit this old project of mine.

This tool does not use Google API.

We have gone beyond one step here from Google by recursively calling the function and appending alphabets from A to Z to the query string to get the complete resultset about that keyword.

For example if you put "paper" as a query the result set will be like :

paper 175,000,000 results
paper airplanes 1,830,000 results
paper mache 403,000 results
paper doll heaven 245,000 results
paper dolls 3,120,000 results
paperdoll heaven 19,100 results
paperport 353,000 results
paperdollheaven 1,780 results
paperchase 72,100 results
paper source 21,700,000 results

I used CURL for this project ,but regex can be used more efectively.

Actually i found this script on net a way back and then heavilly modified it as my webHost was not supporting many functions

putting a snippet here for you to think ahead. P.M. me if you need the complete source.

function buildSuggestUrl($keyword)
return "http://www.google.com/complete/search?hl=en&js=true&qu=" . urlencode($keyword);

PHP Eval

Filed under: PHP at 05:36:19 On 2006-05-07

Well ,this is a slower method (100 times slower sometimes) than direct page rendering.

But ,u get total control over the pagecontent dynamically.

Many a times its safe also to secure your PHP code.The immediate application which i could think of after looking at this function is my own template engine.

function eval_new_helper($arr){
return ("echo stripslashes(\"".addslashes($arr[1])."\");");

function eval_new($string){
$string = "".$string."";
$string = preg_replace("/<\?=\s+(.*?)\s+\?>/", "", $string);
$string = str_replace('?>', '', str_replace( array('((.|\n)*?)<\?/","eval_new_helper",$string) ) );
return eval($string);

// call it from here


Faster Web page rendering

Filed under: PHP at 07:32:35 On 2006-05-04

HTML files for larger sites can become pretty large themselves.

Gzipping or compressing these files has shown to provide a reduction in the neighboorhood of 70-80% of the original file size, a fairly significant 'weight loss'. I did the same thing for my site's index.php and to my surprise the page size came down to 11 KB flat from a huge 90 KB generated HTML.

The Trick

What you need to do is put is ob_start ("ob_gzhandler"); on the top of each page !



We use PHP's ob_gzhandler to send compressed data. This function will first check to see if the browser requesting the file will accept 'gzip,deflate' encoding; if not it sends the file uncompressed. Almost all the browsers support GZip compression. One thing to keep in mind is that , Images are not compressed with this method as only HTML code is rendered via server.