Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, November 14, 2010

PHP :: Using the scope resolution operator



The scope resolution operator is a pair of colons (::). The name of the class goes on
the left side of the operator, and the name of the method or property goes on the right
like this:

ClassName::methodOrPropertyName

PHP doesn't object if you put whitespace on either side of the scope resolution operator,
but the normal convention is to write everything as a single entity.

The scope resolution operator has the following uses:

  • It gives access to overridden properties or methods of a parent class.
  • It is used to call the static methods and properties of a class (this is covered in "Creating static properties and methods" later in this chapter).
  • It gives access to class constants (see "Using class constants for properties" later in the chapter).
  • It is the conventional way of referring to a class method or property in documentation. For example, instead of referring to "the getPageCount() method of the Ch2_Book class," this is shortened to Ch2_Book::getPageCount().
However, PHP provides two handy keywords that work with the scope resolution operator,
namely:
parent: This refers to the parent or any ancestor of the current class.
self: This refers to the current class. Although this sounds the same as $this,
which you met earlier, self refers to the class in general, whereas $this refers to
the current instance of the class (in other words, an object created from the class).

The advantage of the parent and self keywords is that you don't need to change them if
you rename any of the classes to which they refer

Double Dot Means what :: - PHP answers

Double Dot Means what :: - PHP answers:

You could think of it as, just calling that function w/o instantiating
the class that it's in

Tuesday, January 18, 2005

:: PHP :: MYSQL QUERY:TIME ::


DATE_ADD(cst_date, INTERVAL 7 DAY) - CURDATE()) <=7 AND (DATE_ADD(cst_date, INTERVAL 7 DAY) - CURDATE()) >= 0

mysql checking utk list kan tarikh 7 hari dr tarikh tersebut

huh berpeluh jugak.. nk buat checking simple nih...

Sunday, January 09, 2005

::PHP : A-Z Link Generator ::

1) guner ascii key table
2) amik kat zend nyer site
A-Z


for ($i=65;$i<91;$i++) href="%s?letter=%s">%s ', $PHP_SELF, chr($i), chr($i));
}

function chr() nie akan list kan ascii character.. based on thier number

ascii table site

Wednesday, January 05, 2005

::PHP : Continue and Break (Basic) ::

Saper pernah belajar structured programming bender nie pun mmg berguner kat php..

continue......

tugas dier akan stop the loop pas tuh sambung balik klu value dier..
samer ngan condition di beri .. X paham e.g

while (list ($key, $value) = each ($arr)) {
if (!($key % 2)) { // skip odd members
continue;
}
do_something_odd ($value);
}

break
........

loop akan stop jiker meet the condition.. terus berhenti..
dier kuar dr loop Xpaham.. e.g

$arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
while (list (, $val) = each ($arr)) {
if ($val == 'stop') {
break; /* You could also write 'break 1;' here. */
}
echo "$val
\n";
}

nombor lima takkan kuar...

Wednesday, December 22, 2004

:: Compare Date :- BezakaN Masa ::

Anyway, in PHP, the following code sample should help


$dateDiff = mktime(12,0,0,04,20,2003) - mktime(11,0,0,04,20,2003);
echo 'Difference in seconds: ' . $dateDiff . '
';

echo 'Years Difference = '. floor($dateDiff/365/60/60/24);
echo 'Months Difference = '. floor($dateDiff/60/60/24/7/4);
echo 'Weeks Difference = '. floor($dateDiff/60/60/24/7);
echo 'Days Difference = '. floor($dateDiff/60/60/24);
echo 'Hours Difference = '. floor($dateDiff/60/60);
echo 'Minutes Difference = '. floor($dateDiff/60);

evertyhing self explainatory hehe
klu nak compare time better used mktime so u calculation will be correct
.. take from the NET..

Saturday, December 11, 2004

:: Mysql (mysql_fetch_object) ::


mysql_fetch_object

1) akan amik dr database field name... klu mysql_fetch_array kiter akan quote kan
dier nyer row number sbg output..

2) tp mysql_fetch_object klu kiter nk quote kan output dier.. kener guner kan
nama field exactly..


speed wise.. samer jer..
e:g
$row = mysql_fetch_object($result);

/* this is valid */
echo $row->field;
/* this is invalid */
// echo $row->0;


selepas ku membaca manual.. nk buat drop down..

Thursday, December 09, 2004

:: Alternate Color::

$query="SELECT * FROM ".$tablename." WHERE cst_country LIKE '%$s_country%'";
$res=$dbHandle[$DBIndex]->RunQuery($query);
$color1 = "#F7EBDE";
$color2 = "#F7DFCE";

$row_count = 0;
echo"<--table cellspacing=0 cellpadding=0 border=1 valign=top-->";
while ($row = $res->fetchRow()) {
$row_color = ($row_count % 2) ? $color1 : $color2;

$i_value=number_format($row['cst_value'], 3, '.', '');
echo "<--tr bgcolor=\"$row_color\"-->";

echo "<--/tr-->";

$row_count++;
}
echo"<--/table>

1) Declare the desired color $color1 and $color2 and $row_count=0
2) Pastuh letak kan kira2 dier ( $row_color = ($row_count % 2) ? $color1 : $color2; ) dalam looop
3) then letakkan bgcolor=$row_color dlm row kiter
4) buat increment utk row color $row_count++

Tuesday, December 07, 2004

:: Friend code try to translate ::

$_SERVER['HTTP_HOST'] == kuar kan server nyer hostname sesuai msaer nk link kan image so the file is transferable

Tuesday, March 23, 2004

::. InterBIu Question ::.



WHat is the MySQL command to select only 5 rows?? <== I x leh nak jawab cariks kat ittutor nie jwaban die


guner SELEECT matricid,name FROM ayam WHERE name='ahmad' LIMIT 0,5 ;


LIMIT lah funtion dier.. 0-offset and 5 tu diernyer jumlah row


atau leh guner nie


select top 10 * from table_name.



* thanks to paksi N bulan_terang.



2) Pasai table kantoi kat coding.. kener letak td pas tu colpsan="3" ....