Thursday, January 19, 2012

Wednesday, January 18, 2012

SIMPLE CRUD – CODEIGNITER

For this Please follow this link
http://henrihnr.wordpress.com/2009/04/26/simple-crud-application/

Friday, October 14, 2011

How to find the common values of two array, without using array_intersect


$array1 = array(’3′,’8′,’7′,’2′);
$array2 = array(’4′,’5′,’7′,’2′);
$length1=count($array1);
$length2=count($array2);
$common=array();
if ($length1 > $length2)
{
for ($i=0; $i<$length1; $i++)
{
if (in_array($array1[$i], $array2))
{
$common[]=$array1[$i];
}
}
}
else
{
for($i=0; $i<$length2; $i++)
{
if (in_array($array2[$i], $array1))
{
$common[]=$array2[$i];
}
}
}
print ‘
’;

print_r($common);
?>

category sub category program


mysql_connect("localhost","root","");
mysql_select_db("test");
class Categories
{
public function categories_tree($country_id='',$parent='0',$spacer='')
{
$sql = mysql_query("SELECT * FROM categories WHERE parent='$parent'");
$num = mysql_num_rows($sql);
$spacer .= '- ';
while ($row = mysql_fetch_array($sql))
{
if ($num == 0 || $row['parent']=='0')
{
$spacer = '';
}
echo $spacer.'‘.$row['name'].’
‘;
$this->categories_tree($country_id, $row['id'], $spacer);
}
}
}
$cat = new Categories();
$a = ”;
echo $cat->categories_tree(0, $a);
?>

Monday, September 19, 2011


Curl Example

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.h3webdev.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer))
{
    print "Sorry, example.com are a bunch of poopy-heads.
";
}
else
{
    print $buffer;
}

Friday, April 1, 2011

Regular expression for replace special character from an string

$output = preg_replace("/[^A-Za-z0-9]/","",$string_user);

Tuesday, March 29, 2011

When to use InnoDB?


InnoDB uses row level locking, has commit, rollback, and crash-recovery capabilities to protect user data. It supports transaction and fault tolerance.


When to use MyISAM?


MyISAM is designed with the idea that your database is queried far more than its updated and as a result it performs very fast read operations. If your read to write(insert|update) ratio is less than 15% its better to use MyISAM.

MyISAM Or InnoDB MySQL engine?


MyISAM limitations

No Foriegn keys and cascading deletes and updates
No rollback abilities
No transactional integrity (ACID compliance)
Row limit of 4,284,867,296 rows
Maximum of 64 indexes per row


InnoDB Limitations

No full text indexing
Cannot be compressed for fast, read-only

Monday, March 28, 2011

Generate Random 10 digit String


function genRandomString($length) {
    //$length = 10;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';  
    for ($p = 0; $p < $length; $p++)
{
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

   echo strtoupper(genRandomString(10));