$hour = 0;
$min = "00";
while ($hour <= 23) {
$showhour = "";
$showhour = $hour <= 9 ? "0".$hour : $hour;
$select_time[]= $showhour.":".$min.":00";
if ($min == "30") {
$hour++;
$min = "00";
}else{
$min = "30";
}
}
print_r($select_time);
?>
echo $select;
Friday, December 5, 2008
Get Current Month Day Choice Combo Box
function getMonthDays() {
$month_days = array();
////-FUNCTION BODY-////
$month_days[1] = 31;
if (date("L") == 1) { //-'L' in date() returns 1 if its a leap year, 0 if its not.
$month_days[2] = 29;
} else {
$month_days[2] = 28;
}
$month_days[3] = 31;
$month_days[4] = 30;
$month_days[5] = 31;
$month_days[6] = 30;
$month_days[7] = 31;
$month_days[8] = 31;
$month_days[9] = 30;
$month_days[10] = 31;
$month_days[11] = 30;
$month_days[12] = 31;
////-END FUNCTION BODY-////
return $month_days;
}
//Code Start From Here
$monthdays = array();
$monthdays = getMonthDays();
$totdays = 31; //-Total number of days to walk through day choice select.
$day = date("j"); //-'j' in date() returns day of the month without leading zero...[1-31]
$m = date("n"); //-'n' in date() returns month number without leading zero...[1-12] NOT!!! [0-11]...
$i = 0;
while ($i < $totdays) {
$day_array[] = $day;
if ($day == $monthdays[$m]) {
$m++;
$day = 1;
}else{
$day++;
}
$i++;
}
print_r($day_array);
$month_days = array();
////-FUNCTION BODY-////
$month_days[1] = 31;
if (date("L") == 1) { //-'L' in date() returns 1 if its a leap year, 0 if its not.
$month_days[2] = 29;
} else {
$month_days[2] = 28;
}
$month_days[3] = 31;
$month_days[4] = 30;
$month_days[5] = 31;
$month_days[6] = 30;
$month_days[7] = 31;
$month_days[8] = 31;
$month_days[9] = 30;
$month_days[10] = 31;
$month_days[11] = 30;
$month_days[12] = 31;
////-END FUNCTION BODY-////
return $month_days;
}
//Code Start From Here
$monthdays = array();
$monthdays = getMonthDays();
$totdays = 31; //-Total number of days to walk through day choice select.
$day = date("j"); //-'j' in date() returns day of the month without leading zero...[1-31]
$m = date("n"); //-'n' in date() returns month number without leading zero...[1-12] NOT!!! [0-11]...
$i = 0;
while ($i < $totdays) {
$day_array[] = $day;
if ($day == $monthdays[$m]) {
$m++;
$day = 1;
}else{
$day++;
}
$i++;
}
print_r($day_array);
Thursday, October 16, 2008
Get Domain Name Using PHP
echo substr($value_array[$i][Url],7,(int)(strpos($value_array[$i][Url],"/",7) - 7));
?>
?>
Friday, August 22, 2008
Get node count of a "Binary Tree"[Code For Use/db class/Common Function]
/////////////////////Config.php//////////////////////
$hostname_glb = "localhost";
$username_glb = "root";
$password_glb = "";
$database_glb = "sunmax";
$Glb_Node_Array = array();
$Glb_Stack = array();
$Glb_Top = 0;
$Glb_Ptr = NULL;
$Gbl_AllMemberCount=0;
?>
/////////////////////////////////////////////////////////////////
//////////////////////////dbcon_inc.php///////////////////////////////
/////////////////////////////////////////////////////////////////////
include("config.php");
include("classes/dbclass.php");
include("classes/common_functions.php");
$dbobj -> setup_conn($hostname_glb,$username_glb,$password_glb);
$dbcon = $dbobj -> db_connect();
$dbobj -> select_db($database_glb,$dbcon);
?>
/////////////////////////////////////////////////////////////////////
//////////////////////////End dbcon_inc.php///////////////////////
///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
///////////////// Code For Use////////////////////////
//////////////////////////////////////////////////////
include("dbcon_inc.php");
//echo $Gbl_AllMemberCount;
//$Gbl_AllMemberCount=0;
//$_SESSION['sess_mid']);//Root Node Id
global $Glb_Top,$Glb_Ptr,$Glb_Stack,$Glb_Node_Array,$Gbl_AllMemberCount;
$Glb_Top = 0;
$Glb_Stack[$Glb_Top]=NULL;
$Glb_Node_Array =array();
$Gbl_AllMemberCount=0;
$TempFlag = $_SESSION['sess_mid'];
if(strlen($TempFlag) > 0){
$Glb_Ptr=$TempFlag;
$cmobj -> get_all_child_node();
echo (int)($Gbl_AllMemberCount + 1);//this is node count
}else{
echo 0;
}
?>
///////////////////////////////////////////////////////////
///////////////// End Code For Use/////////////////////////
///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////// Common Class //////////////////////////////////
/////////////////////////////////////////////////////////
class common_function extends db{
var $sql = NULL;
var $res = NULL;
var $row = NULL;
var $num = NULL;
//New Function For Node Count
function get_child_root($MID,$LorR){
$this->sql = "SELECT MID FROM tbl_member WHERE SponserID = '$MID' AND Position = '$LorR'";
$this->res = mysql_query($this->sql)or die("1.Error in get_left_child function : ".mysql_error());
$this->num = mysql_num_rows($this->res);
if($this->num > 0){
return $this->get_child($this->res);
}else{
return;
}
}
function get_child($rs){
$this->row = mysql_fetch_object($rs);
return $this->row->MID;
}
function get_all_child_node(){
global $Glb_Top,$Glb_Ptr,$Glb_Stack,$Glb_Node_Array,$Gbl_AllMemberCount;
$this->sql = "SELECT MID FROM tbl_member WHERE SponserID = '$Glb_Ptr' AND Position = 'R'";
$this->res = mysql_query($this->sql)or die("1.Error in get_left_child function : ".mysql_error());
$this->num = mysql_num_rows($this->res);
if($this->num > 0){
$Glb_Top = (int)($Glb_Top + 1);
$Glb_Stack[$Glb_Top] = $this->get_child($this->res);
}
$this->sql = "SELECT MID FROM tbl_member WHERE SponserID = '$Glb_Ptr' AND Position = 'L'";
$this->res = mysql_query($this->sql)or die("2.Error in get_left_child function : ".mysql_error());
$this->num = mysql_num_rows($this->res);
if($this->num > 0){
$Glb_Ptr = $this->get_child($this->res);
$Glb_Node_Array[] = $Glb_Ptr;
}else{
$Glb_Ptr = $Glb_Stack[$Glb_Top];
$Glb_Top = (int)($Glb_Top - 1);
$Glb_Node_Array[] = $Glb_Ptr;
}
if($Glb_Ptr == NULL){
$Gbl_AllMemberCount = (int)(count(array_unique($Glb_Node_Array)));return;
}else{
$this->get_all_child_node();
}
}
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////// End Common Class /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
/**********************************************************************************************/
//////////////THIS DB CLASS CREATED BY ZIYA///////////
/*
1) Functions Description :
(a) setup_conn() [This function used to establish a connection to database]
(b) db_connect() [This function is also used to establish a connection to database]
(c) select_db() [This function is used to select database]
(d) query() [This function is used to execute a query and get result from it]
(e) fetch_array() [This function is used to fetch an array of query result]
(f) num_rows() [This function is responsible for give num of rows]
(g) last_insertid() [This function is give last inserted id]
(h) insert_record() [This function is used to insert a record]
(i) update_record() [This function is used to select record]
(j) delete_record() [This function is used to delete records according to condition]
(k) select_record() [This function is used to select records according to OR condition]
(l) delete_all_record() [This function is used to delete all records from a table]
(m) select_all_record() [This function is used to select all records from a table]
(n) fetchSingleRow($result) [For fetch single record]
(o) executeQuery($query)
(p) select_records() [This function is used to select records according to AND condition]
*/
/***********************************************************************************************/
class db
{
var $hostname;// Hostname that the object should connect to
var $username;// Username that the object should use
var $password;// Password that the object should use
var $database;// Database that the object should use
var $query_num;// counts the total queries that the object has done.
var $con;//contains connection object.
function setup_conn($hostname,$username,$password)
{
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
}
function db_connect()
{
$con = mysql_connect($this->hostname,$this->username,$this->password)or die(mysql_error());/*Open a non persistant connection to the server.*/
if (!$con)
{
echo 'Connection to database server at: '.$this->hostname.' failed.';
return false;
}
else
{
return $con;
}
}
function db_pconnect()
{
$result = mysql_pconnect($this->hostname,$this->username,$this->password);/*Open a persistant connection to the server. */
if (!$result)
{
echo 'Connection to database server at: '.$this->hostname.' failed.';
return false;
}
return $result;
}
function select_db($database,$con)
{
$this->database = $database;
$this->con=$con;
if (!mysql_select_db($this->database,$this->con))
{
'Selection of database: '.$this->database.' failed.';
return false;
}
}
function query($query)
{
$result = mysql_query($query) or die("Query failed:$query
" . mysql_error());
return $result;
}
function fetch_array($result)
{
return mysql_fetch_array($result);
}
function return_query_num()
{
return $this->query_num;
}
function num_rows($result)
{
return mysql_num_rows($result);
}
function last_insertid()
{
return mysql_insert_id();
}
function fetchSingleRow($result)
{
return mysql_fetch_row($result);
}
function delete_all_record($table)
{
$delete_query = "DELETE FROM $table";
$delete_result = mysql_query($delete_query)or mysql_error();
$flag = mysql_affected_rows();
if($flag != 0)
return true;
else
return false;
}
function select_all_record($table)
{
$select_query = "SELECT * FROM ".$table;
$select_result = mysql_query($select_query)or mysql_error();
return $select_result;
}
function select_record($conditon,$table)
{
$len = count($conditon);
$i = 0;
$cond = "";
$sql = "select * from ".$table." where ";
foreach ($conditon as $key => $value) {
if($len - 1 == $i)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$i++;
}
$sql = $sql.$cond;
return mysql_query($sql);
}
function get_row($rs){
$this->row = mysql_fetch_object($rs);
return $this->row;
}
function select_record_with_limit($conditon,$table,$limit)
{
$len = count($conditon);
$i = 0;
$cond = "";
$sql = "select * from ".$table." where ";
foreach ($conditon as $key => $value) {
if($len - 1 == $i)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$i++;
}
echo $sql = $sql.$cond." ".$limit;
return mysql_query($sql);
}
function insert_record($qry,$table)
{
$len = count($qry);
$i = 0;
$field = "";
$data = "";
foreach ($qry as $key => $value) {
if($len - 1 == $i)
{
$field.= $key;
$data.= "'".$value."'";
}
else
{
$field.= $key.",";
$data.= "'".$value."',";
}
$i++;
}
$sql = "insert into ".$table."(".$field.")values(".$data.")";
mysql_query($sql)or die(mysql_error());
//return $this -> last_insertid();
}
function update_record($sql,$conditon,$table)
{
$len = count($sql);
$i = 0;
$data = "";
foreach ($sql as $key => $value) {
if($len - 1 == $i)
$data.= $key."='".$value."'";
else
$data.= $key."='".$value."',";
$i++;
}
$lim = count($conditon);
$j = 0;
$cond = "";
foreach ($conditon as $key => $value) {
if($lim - 1 == $j)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$j++;
}
$sql = "update ".$table." set ".$data." where ".$cond;
mysql_query($sql);
return mysql_affected_rows();
}
function delete_record($conditon,$table)
{
$len = count($conditon);
$i = 0;
$cond = "";
$sql = "delete from ".$table." where ";
foreach ($conditon as $key => $value) {
if($len - 1 == $i)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$i++;
}
$sql = $sql.$cond;
mysql_query($sql);
return mysql_affected_rows();
}
}
$dbobj = new db();
?>
$hostname_glb = "localhost";
$username_glb = "root";
$password_glb = "";
$database_glb = "sunmax";
$Glb_Node_Array = array();
$Glb_Stack = array();
$Glb_Top = 0;
$Glb_Ptr = NULL;
$Gbl_AllMemberCount=0;
?>
/////////////////////////////////////////////////////////////////
//////////////////////////dbcon_inc.php///////////////////////////////
/////////////////////////////////////////////////////////////////////
include("config.php");
include("classes/dbclass.php");
include("classes/common_functions.php");
$dbobj -> setup_conn($hostname_glb,$username_glb,$password_glb);
$dbcon = $dbobj -> db_connect();
$dbobj -> select_db($database_glb,$dbcon);
?>
/////////////////////////////////////////////////////////////////////
//////////////////////////End dbcon_inc.php///////////////////////
///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
///////////////// Code For Use////////////////////////
//////////////////////////////////////////////////////
include("dbcon_inc.php");
//echo $Gbl_AllMemberCount;
//$Gbl_AllMemberCount=0;
//$_SESSION['sess_mid']);//Root Node Id
global $Glb_Top,$Glb_Ptr,$Glb_Stack,$Glb_Node_Array,$Gbl_AllMemberCount;
$Glb_Top = 0;
$Glb_Stack[$Glb_Top]=NULL;
$Glb_Node_Array =array();
$Gbl_AllMemberCount=0;
$TempFlag = $_SESSION['sess_mid'];
if(strlen($TempFlag) > 0){
$Glb_Ptr=$TempFlag;
$cmobj -> get_all_child_node();
echo (int)($Gbl_AllMemberCount + 1);//this is node count
}else{
echo 0;
}
?>
///////////////////////////////////////////////////////////
///////////////// End Code For Use/////////////////////////
///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////// Common Class //////////////////////////////////
/////////////////////////////////////////////////////////
class common_function extends db{
var $sql = NULL;
var $res = NULL;
var $row = NULL;
var $num = NULL;
//New Function For Node Count
function get_child_root($MID,$LorR){
$this->sql = "SELECT MID FROM tbl_member WHERE SponserID = '$MID' AND Position = '$LorR'";
$this->res = mysql_query($this->sql)or die("1.Error in get_left_child function : ".mysql_error());
$this->num = mysql_num_rows($this->res);
if($this->num > 0){
return $this->get_child($this->res);
}else{
return;
}
}
function get_child($rs){
$this->row = mysql_fetch_object($rs);
return $this->row->MID;
}
function get_all_child_node(){
global $Glb_Top,$Glb_Ptr,$Glb_Stack,$Glb_Node_Array,$Gbl_AllMemberCount;
$this->sql = "SELECT MID FROM tbl_member WHERE SponserID = '$Glb_Ptr' AND Position = 'R'";
$this->res = mysql_query($this->sql)or die("1.Error in get_left_child function : ".mysql_error());
$this->num = mysql_num_rows($this->res);
if($this->num > 0){
$Glb_Top = (int)($Glb_Top + 1);
$Glb_Stack[$Glb_Top] = $this->get_child($this->res);
}
$this->sql = "SELECT MID FROM tbl_member WHERE SponserID = '$Glb_Ptr' AND Position = 'L'";
$this->res = mysql_query($this->sql)or die("2.Error in get_left_child function : ".mysql_error());
$this->num = mysql_num_rows($this->res);
if($this->num > 0){
$Glb_Ptr = $this->get_child($this->res);
$Glb_Node_Array[] = $Glb_Ptr;
}else{
$Glb_Ptr = $Glb_Stack[$Glb_Top];
$Glb_Top = (int)($Glb_Top - 1);
$Glb_Node_Array[] = $Glb_Ptr;
}
if($Glb_Ptr == NULL){
$Gbl_AllMemberCount = (int)(count(array_unique($Glb_Node_Array)));return;
}else{
$this->get_all_child_node();
}
}
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////// End Common Class /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
/**********************************************************************************************/
//////////////THIS DB CLASS CREATED BY ZIYA///////////
/*
1) Functions Description :
(a) setup_conn() [This function used to establish a connection to database]
(b) db_connect() [This function is also used to establish a connection to database]
(c) select_db() [This function is used to select database]
(d) query() [This function is used to execute a query and get result from it]
(e) fetch_array() [This function is used to fetch an array of query result]
(f) num_rows() [This function is responsible for give num of rows]
(g) last_insertid() [This function is give last inserted id]
(h) insert_record() [This function is used to insert a record]
(i) update_record() [This function is used to select record]
(j) delete_record() [This function is used to delete records according to condition]
(k) select_record() [This function is used to select records according to OR condition]
(l) delete_all_record() [This function is used to delete all records from a table]
(m) select_all_record() [This function is used to select all records from a table]
(n) fetchSingleRow($result) [For fetch single record]
(o) executeQuery($query)
(p) select_records() [This function is used to select records according to AND condition]
*/
/***********************************************************************************************/
class db
{
var $hostname;// Hostname that the object should connect to
var $username;// Username that the object should use
var $password;// Password that the object should use
var $database;// Database that the object should use
var $query_num;// counts the total queries that the object has done.
var $con;//contains connection object.
function setup_conn($hostname,$username,$password)
{
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
}
function db_connect()
{
$con = mysql_connect($this->hostname,$this->username,$this->password)or die(mysql_error());/*Open a non persistant connection to the server.*/
if (!$con)
{
echo 'Connection to database server at: '.$this->hostname.' failed.';
return false;
}
else
{
return $con;
}
}
function db_pconnect()
{
$result = mysql_pconnect($this->hostname,$this->username,$this->password);/*Open a persistant connection to the server. */
if (!$result)
{
echo 'Connection to database server at: '.$this->hostname.' failed.';
return false;
}
return $result;
}
function select_db($database,$con)
{
$this->database = $database;
$this->con=$con;
if (!mysql_select_db($this->database,$this->con))
{
'Selection of database: '.$this->database.' failed.';
return false;
}
}
function query($query)
{
$result = mysql_query($query) or die("Query failed:$query
" . mysql_error());
return $result;
}
function fetch_array($result)
{
return mysql_fetch_array($result);
}
function return_query_num()
{
return $this->query_num;
}
function num_rows($result)
{
return mysql_num_rows($result);
}
function last_insertid()
{
return mysql_insert_id();
}
function fetchSingleRow($result)
{
return mysql_fetch_row($result);
}
function delete_all_record($table)
{
$delete_query = "DELETE FROM $table";
$delete_result = mysql_query($delete_query)or mysql_error();
$flag = mysql_affected_rows();
if($flag != 0)
return true;
else
return false;
}
function select_all_record($table)
{
$select_query = "SELECT * FROM ".$table;
$select_result = mysql_query($select_query)or mysql_error();
return $select_result;
}
function select_record($conditon,$table)
{
$len = count($conditon);
$i = 0;
$cond = "";
$sql = "select * from ".$table." where ";
foreach ($conditon as $key => $value) {
if($len - 1 == $i)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$i++;
}
$sql = $sql.$cond;
return mysql_query($sql);
}
function get_row($rs){
$this->row = mysql_fetch_object($rs);
return $this->row;
}
function select_record_with_limit($conditon,$table,$limit)
{
$len = count($conditon);
$i = 0;
$cond = "";
$sql = "select * from ".$table." where ";
foreach ($conditon as $key => $value) {
if($len - 1 == $i)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$i++;
}
echo $sql = $sql.$cond." ".$limit;
return mysql_query($sql);
}
function insert_record($qry,$table)
{
$len = count($qry);
$i = 0;
$field = "";
$data = "";
foreach ($qry as $key => $value) {
if($len - 1 == $i)
{
$field.= $key;
$data.= "'".$value."'";
}
else
{
$field.= $key.",";
$data.= "'".$value."',";
}
$i++;
}
$sql = "insert into ".$table."(".$field.")values(".$data.")";
mysql_query($sql)or die(mysql_error());
//return $this -> last_insertid();
}
function update_record($sql,$conditon,$table)
{
$len = count($sql);
$i = 0;
$data = "";
foreach ($sql as $key => $value) {
if($len - 1 == $i)
$data.= $key."='".$value."'";
else
$data.= $key."='".$value."',";
$i++;
}
$lim = count($conditon);
$j = 0;
$cond = "";
foreach ($conditon as $key => $value) {
if($lim - 1 == $j)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$j++;
}
$sql = "update ".$table." set ".$data." where ".$cond;
mysql_query($sql);
return mysql_affected_rows();
}
function delete_record($conditon,$table)
{
$len = count($conditon);
$i = 0;
$cond = "";
$sql = "delete from ".$table." where ";
foreach ($conditon as $key => $value) {
if($len - 1 == $i)
$cond.= $key."='".$value."'";
else
$cond.= $key."='".$value."' and ";
$i++;
}
$sql = $sql.$cond;
mysql_query($sql);
return mysql_affected_rows();
}
}
$dbobj = new db();
?>
Tuesday, June 17, 2008
Get iframe field values in a parent window using javascript
window.framename.document.getElementById(field name).value
Saturday, June 14, 2008
Get Dates Between Two Given Dates
$start = "2008-06-11";
$end = "2008-06-13";
$init_date = strtotime($start);
$dst_date = strtotime($end);
$offset = $dst_date-$init_date;
$dates = floor($offset/60/60/24) + 1;
for ($i = 0; $i < $dates; $i++)
{
$newdate = date("Y-m-d", mktime(12,0,0,date("m", strtotime($start)),
(date("d", strtotime($start)) + $i), date("Y", strtotime($start))));
echo $newdate ."
";
}
?>
$end = "2008-06-13";
$init_date = strtotime($start);
$dst_date = strtotime($end);
$offset = $dst_date-$init_date;
$dates = floor($offset/60/60/24) + 1;
for ($i = 0; $i < $dates; $i++)
{
$newdate = date("Y-m-d", mktime(12,0,0,date("m", strtotime($start)),
(date("d", strtotime($start)) + $i), date("Y", strtotime($start))));
echo $newdate ."
";
}
?>
Thursday, April 17, 2008
Get Number Of Days Between Two Days
$FromDate = date("Y-m-d");
$ToDate = date("Y-m-d", mktime(0,0,0,date("m"),date("d")+6,date("Y")));
$nuber_of_days = date('d',mktime(0,0,0,date("m"),date("d")+6,date("Y")) - mktime(0,0,0,date("m"),date("d"),date("Y")));
if(substr($nuber_of_days,0,1) == 0)
$nuber_of_days = substr($nuber_of_days,1,1);
$ToDate = date("Y-m-d", mktime(0,0,0,date("m"),date("d")+6,date("Y")));
$nuber_of_days = date('d',mktime(0,0,0,date("m"),date("d")+6,date("Y")) - mktime(0,0,0,date("m"),date("d"),date("Y")));
if(substr($nuber_of_days,0,1) == 0)
$nuber_of_days = substr($nuber_of_days,1,1);
Get All Dates Of Current Week
for($d=0;$d<=6;$d++)
{
$i = $d;
$newdate = mktime(0,0,0,date("m"),date("d")+$i,date("Y"));
$weekdate = date("Y-m-d", $newdate);
}
{
$i = $d;
$newdate = mktime(0,0,0,date("m"),date("d")+$i,date("Y"));
$weekdate = date("Y-m-d", $newdate);
}
Subscribe to:
Posts (Atom)