473,785 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = getUnkownKeyVal ues( $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,
$itemDescriptio n = "";

function getFileName()
{
return $fileName;
}

function ShoppingCenter( $itemArray )
{
$this->iArray = $itemArray;
$this->itemNumber = $itemArray[0];
$this->itemDescriptio n = $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( !ifSectionExisi ts( $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($ite mList);$i++)
{
foreach($itemLi st[$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 1652

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

Similar topics

8
2092
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, I've been playing with Qt in KDE on a Slackware 10.0 system, and following their cookbook exercises, and everything's working, and I have no clue what the code is doing, i.e.. how do I connect my brain to the ascii in the files to the stuff on...
17
2076
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 write a signature for the developer and after getting a good start developing a 2.0 application I thought I should go through the code and start marking classes and with namespaces. I keep getting the following 'missing' error even when using a first...
15
1233
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 song-lyrics editing tool, pretty simple - a couple of textboxes and a button or 2 to save/load from text files, but I want something along the lines of a drivelistbox/dirlistbox/filelistbox combo down the side to easily open saved files. Also - how...
13
1320
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 = 0 Public Shared Sub Increment() SyncLock (m_lock)
8
1113
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 looked at the createwindowex function an have to admit ... im baffled. What id like to do is run a function or proc that will pop up a dialog box with a progress bar on and be able to pass values to the progressbar, then distroy the dialog box...
2
1323
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 knowledge of HTML, XML, XSL, JSP, Javascript, SQL & ISS (Internet Information server) ... They also want the candidate to know Dreamweaver and some Flash. I know Frontpage. Is there anyplace on the internet where I can take a crash course and gain some...
22
2116
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 a class, that when implemented, they require the implementing calss to make sure that each of the properties, functions etc. are handled by the class. (????) What I am really having a problem with is how they overcome the limitation
20
1900
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 point, then I can add attributes any time, and at any place in the program? 2) Are classes typically created like this: class Point:
5
1298
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 classes in VC++/CLI: Unmanaged classes (i.e. normal classes compiled in a unmanaged source or dll , the code is unmanaged and CPU native). Accessible from C++/CLI
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.