Ask a Question related to PHP Development, Design and Development.
-
todd #1
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.
todd Guest
-
AWEDBFILES4 ?? I don't understand!
No one in other forums were able to help me so I will try here now. I have legit versions of all of my Adobe programs and I have registered 1 of... -
If you can understand DBI internals...
and how it links up to DBD::mysql, then you are pretty close to Perl God. Because I can't make heads or tails of it. But I can tell that... -
Do not understand Hashes !
I have a problem with hashes and trying to understand them, I have read the perldoc intersection and looked into the Perl Cookbook, and still do... -
I don't understand why this happen
open my $fh, "<", "items/list.db"; print while (<$fh>); close $fh; This is suppose to printout the content in items/list.db , but why I get... -
[PHP] I don't understand...
Jason Martyn wrote: You're trying to assign to a function, seriousley messed up. I reccomend you make sure you know PHP before going any...



Reply With Quote

