Convert number of seconds to readable time format

The php version:

[php]

function formatTime($secs) {
$times = array(3600, 60, 1);
$time = ”;
$tmp = ”;
for($i = 0; $i < 3; $i++) {
$tmp = floor($secs / $times[$i]);
if($tmp < 1) {
$tmp = ’00’;
}
elseif($tmp < 10) {
$tmp = ‘0’ . $tmp;
}
$time .= $tmp;
if($i < 2) {
$time .= ‘:’;
}
$secs = $secs % $times[$i];
}
return $time;
}

[/php]

And the JS version:

[js]
function formatTime(secs){
var times = new Array(3600, 60, 1);
var time = ”;
var tmp;
for(var i = 0; i < times.length; i++){
tmp = Math.floor(secs / times[i]);
if(tmp < 1){
tmp = ’00’;
}
else if(tmp < 10){
tmp = ‘0’ + tmp;
}
time += tmp;
if(i < 2){
time += ‘:’;
}
secs = secs % times[i];
}
return time;
}
[/js]

PHP Simple Paginator Code

This is a simple example of mysql table pagination using PHP code.

Please see attached zip for refference.

This is the index.php file bellow:

[php]

/*
in config.php you define the database connection.
$limit defines the limit of items per page
$adjacents number of adiacent items on paginator
*/
include(‘config.php’);

$tbl_name="mapstories_stories";

$adjacents = 3;

$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query)) or die(mysql_error());
$total_pages = $total_pages[‘num’];

$targetpage = "index.php";
$limit = 5;
$page = $_GET[‘page’];
if($page)
$start = ($page – 1) * $limit;
else
$start = 0;

$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);

if ($page == 0) $page = 1;
$prev = $page – 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage – 1;

$pagination = "";
if($lastpage > 1)
{
$pagination .= "

n";
}
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<table>
<tr>
<th>ID</th>
<th>Lat</th>
<th>Lng</th>
</tr>
<?php $i = 0;
while($row = mysql_fetch_array($result)) {?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $row[‘lat’];?></td>
<td><?php echo $row[‘lng’];?></td>
</tr>
<?php }?>
</table>
<?=$pagination?>

</body>
</html>

[/php]

And the config.php:

[php]

mysql_connect(‘localhost’, ‘root’, ”) or die(mysql_error());
mysql_select_db(‘mapstories’) or die(mysql_error());

[/php]

And a small style.css – this one is using Cakephp’s default table styles 😉

[css]

body{
font-family:arial;
font-size:11px;
}
div.pagination {
padding: 3px;
margin: 3px;
}

div.pagination a {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #AAAADD;
zoom: 100%;
text-decoration: none; /* no underline */
color: #000099;
}
div.pagination a:hover, div.pagination a:active {
border: 1px solid #000099;

color: #000;
}
div.pagination span.current {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #000099;

* zoom: 100%;

font-weight: bold;
background-color: #000099;
color: #FFF;
}
div.pagination span.disabled {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #EEE;

* zoom: 100%;

color: #DDD;
}

* span.elipsis {zoom:100%}

/** Tables **/
table {
background: #fff;
border-right:0;
clear: both;
color: #333;
margin-bottom: 10px;
width: 100%;
}
th {
border:0;
border-bottom:2px solid #555;
text-align: left;
padding:4px;
}
th a {
display: block;
padding: 2px 4px;
text-decoration: none;
}
th a.asc:after {
content: ‘ ⇣’;
}
th a.desc:after {
content: ‘ ⇡’;
}
table tr td {
background: #fff;
padding: 6px;
text-align: left;
vertical-align: top;
border-bottom:1px solid #ddd;
}
table tr:nth-child(2n) td {
background: #f5f5f5;
}
table .altrow td {
background: #f5f5f5;
}
td.actions {
text-align: center;
white-space: nowrap;
}
table td.actions a {
margin: 0px 6px;
padding:2px 5px;
}[/css]

Click the following link to download all this code: php_pagination

Weird and Amazing Animal Facts

When I have been travelling around your world I have learnt things about animals that are really weird.

I am going to make a list of animal facts that I think are the weirdest or funniest I have heard.

They could be true. Why don’t you do some research yourself and see if they are.

  • Penguins can jump 6 feet in the air.
  • A group of Kangaroos is called a mob.
  • A young Kangaroo is called a Joey.
  • Emus and kangaroos cannot walk backwards.
  • Beavers can hold their breathe for 45 minutes under water.
  • The smallest bird in the world is the Humming Bird. It weighs less than 1 oz (or 1g).
  • A bear can run at speeds of up to 30 miles per hour (48 km/h).
  • Elephants are the only animal that can’t jump.
  • Polar bears are left handed.
  • A crocodile cannot stick its tongue out.
  • A cat has 32 muscles in each ear.
  • Tigers have striped skin not just striped fur.
  • Reindeer eat moss because it contains a chemical that stops their body from freezing.
  • The coyote’s scientific name (Canis Latrans) means ‘barking dog’.
  • Snakes can see through their eyelids.
  • A Woodpecker can peck 20 times per second.
  • Woodpeckers don’t get headaches from all that pecking. Their skulls have air pockets to cushion the brain.
  • Katydids have ears in their front legs.
  • The praying mantis is the only insect that can turn its head 360 degrees.
  • Butterflies tast sensors are in their feet. They taste their food by standing on it.
  • The strongest animal in the world is the rhinoceros beetle. It can lift 850 times its own weight.
  • Flamingos are pink because shrimp is one of their main sources of food.
  • The flying frog uses flaps of skin between its toes to glide.
  • The slowest mammal on earth is the tree sloth. It only moves at a speed of 6 feet (1.83 meters) per minute.
  • The Chameleon’s tongue is as long as its body.
  • The Chameleon can focus its eyes seperately to watch two objects at once.
  • The Kangaroo’s ancestors lived in trees. Today there are eight different kinds of tree kangaroos.
  • Flamingos eat with their heads upside down to strain the water out of their food.
  • Many snakes never stop growing. That’s one reason they must shed their skin.
  • The Artic Tern flies from the North Pole to the South Pole and then back again to spend summer in each place.
  • The black bulldog ant from Australia is the most dangerous ant in the world. It stings and bites at the same time and has killed humans.
  • A hippopotamus can stay under water for up to 30 minutes.
  • The Basenji is the only dog which does not bark.
  • Armadillos, opossums and sloths spend up to 80 percent of their lives sleeping.

Pink Iguana Species Discovered

Ping IguanaA new species of Galápagos iguana has scientists tickled pink.
The pink iguana, named after its salmon-colored skin, lives only on the Wolf volcano on the island of Isabela.
Charles Darwin did not visit the volcano on his travels to the Ecuadorian island chains in the 1830s, so the creature remained undiscovered until 1986, when it was spotted by park rangers. Only now has it been recognized as its own species.
Gabriele Gentile, of Rome’s University Tor Vergata, and colleagues are the first team to research and document the iguana, which will receive a formal scientific name in an upcoming paper. Continue reading Pink Iguana Species Discovered