RE: [PHP] classes?
| From: | Maxim Maletsky | Date: | Thu, 16 Nov 2000 06:24:08 +0000 |
| Subject: | RE: [PHP] classes? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25628@lists.php.net to get a copy of this message | ||
I think your problem is GLOBALS,
you need to specify variables from outside the functions in order to use
them:
class add_item {
var $product;
var $quantity;
function f1() {
...
}
function f1() {
...
}
function f1() {
...
}
function set() {
GLOBAL $product,$quantity;
$this->produt = $product;
$this->quantity = $quantity;
}
}
you will need to call set() at the first function that need these variables.
this is how globasls work.
hope it is usfull in case you didn't know it.
Cheers,
Maxim Maletsky
-----Original Message-----
From: Kurth Bemis [mailto:kurth@usaexpress.net]
Sent: Thursday, November 16, 2000 3:17 PM
To: php-general@lists.php.net
Subject: [PHP] classes?
ok all i'm just starting to get involved with classes...and have a slight
problem......i don't understand how to access functions..i have been
reading the manual at php.net but that confuses even more....take a look at
some code i wrote...
print "<a href=\"$PHP_SELF?product=$product&quanity=1\">$title -
$price</a>";
thats to add a item to my cart......
the class function looks like this...
function add_item($table, $session, $product, $quantity) {
$qty = $this->check_item($table, $session, $product);
if($qty == 0) {
$query = "INSERT INTO $table (session, product, quantity)
VALUES ";
$query .= "('$session', '$product', '$quantity')
";
mysql_query($query);
} else {
$quantity += $qty;
$query = "UPDATE $table SET quantity='$quantity' WHERE
session='$session' AND ";
$query .= "product='$product' ";
mysql_query($query);
}
}
my question is how to i pass that vars that i need to the class? am i
making sense here?
~kurth
Kurth Bemis - Network/Systems Administrator, USAExpress.net/Ozone Computer
There is no sin except stupidity. -- Oscar Wilde
kurth@usaexpress.net | http://www.usaexpress.net/kurth
PGP key available - http://www.usaexpress.net/kurth/pgp
Fight Weak Encryption! Donate your wasted CPU cycles to Distributed.net
(http://www.distributed.net)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net