Home

Efficient Result Row Counting from MySQL

$query = 'SELECT COUNT(*) FROM sometable';
$result = mysql_query($query,$connection);
list($count) = mysql_fetch_array($result);



Finding Yesterday's Date

$yesterday = mktime( 0, 0, 0, date("m") , date("d")-1, date("Y") );
print date( "Y-m-d", $yesterday );



Store an array in a cookie via the serialize function:

function set_array_cookie($cookiename, $arrayvar, $seconds_to_live) {
  setcookie($cookiename, serialize($arrayvar), time()+($seconds_to_live));
}

Retrieve a serialized array from a cookie.

The stripslashes function is necessary because serialize adds them automatically before it does its magic.

function get_array_cookie($cookiename) {
  return unserialize(stripslashes($_COOKIE[$cookiename]));
}



If you find this page useful, please consider making a secure donation:

Creative Commons Attribution Share-Alike License logo
This work is copyright © 2002-2008 Bruce Timberlake and is licensed under a Creative Commons Attribution Share-Alike License. It may be copied, modified, and distributed freely as long as it attributes the original author by name ("Bruce Timberlake") and URL ("http://brucetimberlake.com/") and maintains the original license. See the license for details.