473,228 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

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;
(showCart.php)
<?php
require( 'ShoppingCenter.php' );

$item = new ShoppingCenter( $itemArray );

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

This is the ShoppingCenter class:
note that the inifunc.php is code i writen/found to write out to a
file.
(ShoppingCenter.php)
<?php
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:
(showCart.php)
<?php
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 1630

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
17
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not...
15
by: Alex McMillan | last post by:
Hey - I know a bit about vb, written a few progs, upgraded to .net 2003 but can't figure it out. Where has everything gone? Am I missing something really obvious? I'm trying to create a...
13
by: cj | last post by:
Stephany Young provided me with the following code to count threads created by my program. Public Class MyThreadCount Private Shared m_lock As New Object Private Shared m_threadcount As Int32...
8
by: Peter Newman | last post by:
Im running vb.net 2003. Im still on a big learning curve with .net and like most people have great ideas on what id like a peice of software to do.... but lack the knowledge to do it I have...
2
by: ShannonATL | last post by:
Does anyone know where I can find any information on any of these languages. I am interviewing for a very entry level position as a web designer. They would prefer that the right candidate have...
22
by: RSH | last post by:
Hi, I have been reading on interfaces working on samples I've run across on the web. For the life of me I cannot seem to grasp them. It appears to me that interfaces are simply blueprints to...
20
by: walterbyrd | last post by:
Reading "Think Like a Computer Scientist" I am not sure I understand the way it describes the way objects work with Python. 1) Can attributes can added just anywhere? I create an object called...
5
by: QbProg | last post by:
Hello, I did some experiments with VC++ 2005, and some ILDasm. Please tell me if I have understood the concepts of C++ programming under .NET, since I'm a bit confused! -- There are 4 types of...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.