ICC WORLD CUP 2011 WATCH LIVE ONLINE

How to access database using PHP

1:32 PM Posted by: Isuru Jayathissa 0 comments

$db = "Netplexer"; // Here name of the database

$link = mysql_connect("localhost","root","" ); // Setp 1 , connection... .
// here I use default setting of Mysql database

if ( ! $link )

die( "Couldn't connect to MySQL" ); // error massage


mysql_select_db( $db, $link ); // Step 2 , select database
or die ( "Couldn't open : ".mysql_error() );

$query = "SELECT DST_IP,// Step 3 , Mysql query ,
COUNT(DST_IP) AS NumOccurrences
FROM IncomingTraffic
GROUP BY DST_IP
HAVING ( COUNT(DST_IP) > 1 )
ORDER BY NumOccurrences DESC";


// here we can use Select , Insert , drop , etc ..

$result=mysql_query( $query) or die (mysql_error());
$i=0;

while($row=mysql_fetch_array($result)) // separate data using arrays
{

$data []= $row['NumOccurrences'];
$dataIP []= $row['DST_IP'];

}

mysql_close( $link ); // Step 4 , Close

How to get time difference using php

6:09 PM Posted by: Isuru Jayathissa 0 comments

function nicetime($date)
{
if(empty($date)) {
return "No date provided";
}

$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");

$now = time();
$unix_date = strtotime($date);

// check validity of date
if(empty($unix_date)) {
return "Bad date";
}

// is it future date or past date
if($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";

} else {
$difference = $unix_date - $now;
$tense = "from now";
}

for($j = 0; $difference >= $lengths[$j] && $j <>
$difference /= $lengths[$j];
}

$difference = round($difference);

if($difference != 1) {
$periods[$j].= "s";
}

return "$difference $periods[$j] {$tense}";
}

$date = "2009-10-07 14:00";
$result = nicetime($date);

echo $result;

How to get line of string from a text file

6:14 PM Posted by: Isuru Jayathissa 0 comments

function getstrline($searchstr, $file){$myfile = file($file);$key = array_search($searchstr, $myfile);
return (
"'$searchstr' at line nomber: $key");
}

Echo
getstrline("This is the String that we want to find", "sometest.txt");?>

 


2009 Isuru's Blog. All rights reserved.
.
For the more details..,
keijayathissa@gmail.com