Saturday, May 31, 2014

How To Find & Replace String using Mysql Query

if you  find a string in a certain field and replace it with another string in database table. Please use below code.








syntax:
update [table_name] set [field_name] = replace([field_name],’[string_to_find]‘,’[string_to_replace]‘);
or
 UPDATE `table_name`
 SET `field_name` = replace(same_field_name, 'unwanted_text', 'wanted_text')

For Exp:
update user set name = replace(name,’Gupta’,'Mishra’);

Friday, May 30, 2014

Display Page Execution Time Using Php

Use this Small code to check the execution time of your script.

<?php
// Write this line at the top of script
$start = (float) array_sum(explode(‘ ‘,microtime()));

/*
your code here
*/

// Write these lines at the bottom of script
$end = (float) array_sum(explode(‘ ‘,microtime()));
echo sprintf(“%.4f”, ($end-$start));
?>



If you want to increase the execution time limit then use these:

1. set_time_limit(int $seconds)

(See it – will not work in Safe Mode)

2. ini_set(‘max_execution_time’, 300); //300 seconds = 5 minutes

(See it – ini_set will not work in Safe Mode)

3. Via .htaccess

php_value max_execution_time 90

4. Also set php.ini - This maximum execution time limit is set inside the php.ini file like this.
max_execution_time = 30; Maximum execution time of each script, in seconds



For Example


<!--  this  code at the top of the page -->
<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;
;?>



<!--  this code at the bottom of the page -->
<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";
;?>

output
This page was created in 0.0027 seconds.

Friday, May 23, 2014

Multiple Drop Down out put one container

Following code very useful select one value of multi drop down (select) , show out put value define  container.

Js is pick this url: mootools-core-1.4.5-nocompat.js



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Multiple Drop Down out put one container</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<script type='text/javascript' src='mootools-core-1.4.5-nocompat.js'></script>
<script language="javascript">

function run(val) {


if(val==1)
{
document.getElementById("srt").innerHTML = document.getElementById("Ultra").value;
document.getElementsByName("Ultra2")[0].value="drop2";
document.getElementsByName("Ultra3")[0].value="drop3";
}
else if(val==2)
{
document.getElementById("srt").innerHTML = document.getElementById("Ultra2").value;
document.getElementsByName("Ultra")[0].value="drop1";
document.getElementsByName("Ultra3")[0].value="drop3";

}

else if(val==3)
{
document.getElementById("srt").innerHTML = document.getElementById("Ultra3").value;
document.getElementsByName("Ultra")[0].value="drop1";
document.getElementsByName("Ultra2")[0].value="drop2";

}
else{
document.getElementsByName("Ultra")[0].value="drop1";
document.getElementsByName("Ultra2")[0].value="drop2";
document.getElementsByName("Ultra3")[0].value="drop3";
}


}




</script>


</HEAD>

<BODY  onLoad="run()">


<table cellpadding="10" cellspacing="10" ><tr><td>
Drop1 <select id="Ultra" onchange="run(1)" name="Ultra" >  <!--Call run() function-->
     <option value="drop1">Select</option>
     <option value="1">text1</option>
     <option value="2">text2</option>
     <option value="3">text3</option>    
</select></td>
<td>
Drop2 <select id="Ultra2" onchange="run(2)" name="Ultra2" >  <!--Call run() function-->
     <option value="drop2">Select</option>
     <option value="4">text4</option>
     <option value="5">text5</option>
     <option value="6">text6</option>    
</select></td>
<td>

Drop3 <select id="Ultra3" onchange="run(3)" name="Ultra3" >  <!--Call run() function-->
     <option value="drop3">Select</option>
     <option value="7">text7</option>
     <option value="8">text8</option>
     <option value="9">text9</option>    
</select></td>
</tr></table>

<!-- main container Start -->
<div id="srt" style="padding:0 0 0 20px;">OutPut Area </div>
<!-- main container End -->

</BODY>
</HTML>