Wednesday, November 28, 2007

linking parent and child with same table

SELECT a.menu_name, b.menu_name
FROM menu AS a, menu b
WHERE a.parent_id = b.menu_id

Powered by ScribeFire.

Monday, November 26, 2007

how to catch 404 in .htaccess

ErrorDocument 404 /notfound.html

Powered by ScribeFire.

Thursday, November 22, 2007

radio button validation

function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
if (btn[i].checked) {cnt = i; i = -1;}
}
if (cnt > -1) return btn[cnt].value;
else return false;
}

Powered by ScribeFire.

Saturday, November 17, 2007

This_month_first

This month first

Mysql-format
date("Y-m")."-1";
php
"1-".date("m-Y");

This year first
Mysql-format
date("Y")."-01-1";
php
"1-01-".date("Y");


Powered by ScribeFire.

day of the year

z - day of the year; i.e. "0" to "365", so:

$day_number=date("z");

This returns January 1 as being 0. If you want the day numbers to be
the usual 1-365 then you should use:

$day_number=date("z")+1;

Powered by ScribeFire.

Wednesday, November 14, 2007

get current url from php

echo $HTTP_SERVER_VARS["HTTP_HOST"] . $HTTP_SERVER_VARS["REQUEST_URI"];

Powered by ScribeFire.

Saturday, November 10, 2007

HAVING

SELECT column,SUM(column) FROM table
GROUP BY column
HAVING SUM(column)

Powered by ScribeFire.

Friday, November 09, 2007

now_in_mysql()

function now_in_mysql()
{
$sql="select NOW()";
$res=dbquery($sql,"single");
return($res[0]);
}

Powered by ScribeFire.

get_unix_time_stamp($timestamp)

function get_unix_time_stamp($timestamp)
{
$res=dbquery("SELECT UNIX_TIMESTAMP('$timestamp')","single");
return($res[0]);


}

Powered by ScribeFire.

add_date_with_today($days)

function add_date_with_today($days)
{

$sql="select DATE_ADD(CURRENT_DATE(),INTERVAL ".addslashes($days)." day)";


$dat=dbquery($sql,"single");
return(toUkDate($dat[0]));

}

Powered by ScribeFire.