470,848 Members | 1,569 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Im trying to understand php classes please help

Im tring to learn about classes with php. I've read alot of posts here
and look at other peoples code. So I appied all the absorbed to this.
Im tring to build a Shopping cart. not for live use but just to learn
about classes and get better at php. Anyway, i put this code together
and can't get it to work. it may be comletely wrong and if it is
please direct me to a good tutorial.
But at the risk of looking like a complete ass. here is my code.
please be kind.

A page calls a page with this code;
require( 'ShoppingCenter.php' );

$item = new ShoppingCenter( $itemArray );

$itemList = getUnkownKeyValues( $item->getFileName() );

This is the ShoppingCenter class:
note that the inifunc.php is code i writen/found to write out to a
include( 'inifunc.php' );

class ShoppingCenter
var $fileName = "tfsmc.txt";
var $iArray;
var $qty = 0,
$itemNumber = 0,
$itemCost = 0,
$totalCost = 0,
$itemDescription = "";

function getFileName()
return $fileName;

function ShoppingCenter( $itemArray )
$this->iArray = $itemArray;
$this->itemNumber = $itemArray[0];
$this->itemDescription = $itemArray[1];
$this->itemCost = $itemArray[2];
$this->qty = $itemArray[3];

$totalCost = $qty * $itemCost;
$totalCost = number_format($totalCost, 2, '.', '');
$this->iArray[2] = $totalCost;

function addToCart()
if( !ifSectionExisits( $itemNumber ) )
foreach( $iArray as $key => $value )
write_key($this->itemNumber, $key, $value, $this->file_name);

After the ShoppingCenter is called the showCart.php "SHOULD" display
what was writen to the file:
for($i = 0;$i<count($itemList);$i++)
foreach($itemList[$i] as $key => $value)
if( $key == "removed")break;
echo "<td>$value</td>";
if( $key == "totalCost" )echo"<td><div align='center'><input
type='submit' name='Submit' value='Remove'></div></td></tr>";
if more is needed please let me know and if this just sucks please let
me know. also i know that there are probably much better ways of doing
things like using sessions and such. but like i said i just want to
learn .
Thanks a million in advance.
Jul 17 '05 #1
0 1536

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rich Grise | last post: by
13 posts views Thread by cj | last post: by
8 posts views Thread by Peter Newman | last post: by
22 posts views Thread by RSH | last post: by
20 posts views Thread by walterbyrd | last post: by
5 posts views Thread by QbProg | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.