Thursday, 18 December 2014

Mysql:: Stored Procedure:: Looping Daily Date With Time Range

PROCEDURE abc(pmId INT, dateFrom DATE, dateTo DATE)
BEGIN
        DECLARE str TEXT;
        DECLARE dff DATETIME;
        DECLARE dnn DATETIME;
        DECLARE dn DATE;
    DECLARE df DATE;
    SET df = dateFrom;
    WHILE DATE(df) <= DATE(dateTo) DO
            SET dn = DATE_ADD(df, INTERVAL 1 DAY);
  
            SET dff = CONCAT(df, ‘ 08:00:00′);
            SET dnn = CONCAT(dn, ‘ 07:59:00′);
  
            SELECT ‘CT1′ as trip, DATE_FORMAT(date,’%d-%m-%Y’) as date,GROUP_CONCAT(DISTINCT CAST(driver_id AS CHAR)) as  
                        dri, count( IF(size=20, 1, NULL ) ) AS ctOne20, count( IF(size=40, 1, NULL ) ) AS ctOne40
            FROM trip_ct WHERE pm_id=pmId AND DATE_ADD(date, INTERVAL time HOUR_SECOND) BETWEEN dff AND dnn;
            SET df = DATE_ADD(df, INTERVAL 1 DAY);
               
    END WHILE;
END

Replace space in Java Script

var course = “The Style And CSS”;
var rep_course = course.replace(/ /g, “-“); //replace all space with -

Jquery:: add table row, remove table row

<script type=”text/javascript”>
function addRowTable()
{
$(“#myTable > tbody”).append(“<tr><td>row content</td></tr>”);
}
function removeRowTable(rowId)
{
if(confirm(“Are you sure to delete this item?”)){
$(“#”+rowId).remove();
}
}
</script>
<table id=”myTable”>
<thead><th>head1</th></thead>
<tbody></tbody>
</table>
<input type=”button” name=”addtolist” value=”Add To List” onclick=”addRowTable()”>

Php compare strings and compute differences

Here is the php source code on how to compare two strings and compute the differences.
<?php
$text1 = $text1 = $s = ”;
if(isset($_POST[‘submit’]))
{
$text1 = $_POST[‘text1′];
$text2 = $_POST[‘text2′];
$chk = $_POST[‘chk’];
if($chk == ‘y’)
{
$s = ‘checked';
}
}
echo “<form method=post action=’strCompute.php’>
Text 1: <input type=text name=’text1′ value=’$text1′>
Text 2: <input type=text name=’text2′ value=’$text2′>
<input type=’checkbox’ name=’chk’ value=’y’ $s> Case Insensitive?
<input type=submit value=’Submit’ name=’submit’>
</form>”;
if($text1 == ”){ exit; }
$arrResult = computeDiff($text1, $text2, $chk);
$cntResult = count($arrResult);
echo “<p>Total Distance is $cntResult</p>”;
echo “<p>The differences character are:”;
foreach($arrResult as $value)
{
echo ” <font color=red><b>$value</b></font> “;
}
echo “</p>”;
function computeDiff($text1, $text2, $chk)
{
if($chk == ‘y’)
{
$text1 = strtolower($text1);
$text2 = strtolower($text2);
}
$array1 = str_split($text1);
$array2 = str_split($text2);
$result = array_diff_assoc($array1, $array2);
if(count($result) == 0)
{
$result = array_diff_assoc($array2, $array1);
}
return $result;
}
?>

JpGraph – Generate PHP graph and YII Charts

JpGraph is a Object-Oriented Graph creating library for PHP >= 5.1 The library is completely written in PHP.
I’m using this classess to create any graph over the years. It is easy to use and a lot of function to customize your graph output.
Create graphical statistic or analysis using this classess. Obsolutely easy and free also.
Support Supports several plot types,spider-plots, pie-charts (both 2d and 3d) , scatter-plots, line-plots, filled line-plots, accumulated line-plots, bar plots, accumulated bar plots, grouped bar plots, error plots, line error plots, box plots, stock plots.
Get JpGraph here -> JpGraph

Nice and Interactive Chart :: With Yii Extensions

Nice and Interactive Chart With Yii Extensions

For Yii extensions: