B4mBi Développement Web / Administration Système

16juil/111

web [PHP] class

<?php
//
//  class_item.php
//  brève
//
//  Created by Bambi on 2011-07-16.
//  Copyright 2011 Bambi. All rights reserved.
// 

class Item {
	protected $itemName, $itemPrice, $itemQuantity;

	public function __construct($itemName, $itemPrice, $itemQuantity) {
		$this->name = $itemName;
		$this->price = $itemPrice;
		$this->quantity = $itemQuantity;
		$this->total();
	}
	protected function total() {
		$this->price = number_format($this->price, 2);
		$this->total = number_format(($this->price * $this->quantity), 2);
	}
	public function __toString() {
		return 	"<tr>" .
			   	"	<td>$this->name</td>" .
			   	"	<td>$this->quantity</td>" .
			   	"	<td>$this->price\mce_markerlt;/td>" .
			   	"	<td>$this->total\mce_markerlt;/td>" .
			   	"</tr>";
	}
}
?>
<!--
      p_item.html
      brève

      Created by Bambi on 2011-07-16.
      Copyright 2011 Bambi. All rights reserved.
 -->
<?php
include('class_item.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<table>
	<tr>
		<td width="120">Désignaton</td>
		<td width="50">Qu</td>
		<td width="60">Px</td>
		<td>Total</td>
	</tr>
	<?=$item1=new Item('Boulet en bonze', 15, 5); ?>
	<?=$item2=new Item('Fouet en cuir', 5, 15); ?>
</table>
<b>Total :</b> <?=$item1->total+$item2->total ?>$
</body>
</html>
<?php unset($item1, $item2); ?>

Content de cet article?

Inscrivez vous à notre fil rss!

Remplis sous: Laisser un commentaire
Commentaires (1) Trackbacks (0)
  1. Dédicacé à Marc !


Laisser un commentaire


Aucun trackbacks pour l'instant