I would rewrite your class slighly like this:
1. pass $ponum into the class during the constructor
2. since you're passing in $item into each function, no need to have it as
an attribute
class PurchaseOrder
{
//Variables
var $ponum; //This will be a $_SESSION variable if that matters
function PurchaseOrder($ponum){
$this->ponum = $ponum;
}
function AddItem($item){
...INSERT SQL CODE using $this->ponum
}
function DeleteItem($item){
...DELETE SQL CODE using $this->ponum
}
function UpdateItem($item){
...UPDATE SQL CODE using $this->ponum
}
function ListItems(){
...SELECT SQL CODE using $this->ponum, RETURN RESULTS (ie.
while($row=mssql_fetch_array($rst)){echo $row[0]....})
}
}
?>
HTH
Martin
> -----Original Message-----
> From: Mike Smith [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, 16 December 2003 10:22 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Starting OOP
>
>
> I've been doing procedural coding for a few month's, but perceive the
> need for OOP for some of the projects I've done. I'm starting out and
> and would like some feedback, before I tread down the wrong path. The
> books I'm looking at Professional PHP (Wrox), and Visual
> QuickStart PHP
> have examples, but I seem to need something more concrete so I've
> started a skeleton to rewrite a Purchase Order application.
> Here is the
> layout:
>
> <?php //pocode.php
> class PurchaseOrder
> {
> //Variables
> var $ponum; //This will be a $_SESSION variable if that matters
> var $item;
>
> function AddItem($ponum,$item){
> ...INSERT SQL CODE
> }
>
> function DeleteItem($ponum,$item){
> ...DELETE SQL CODE
> }
>
> function UpdateItem($ponum,$item){
> ...UPDATE SQL CODE
> }
>
> function ListItems($ponum){
> ...SELECT SQL CODE, RETURN RESULTS (ie.
> while($row=mssql_fetch_array($rst)){echo $row[0]....})
> }
>
> }
> ?>
>
> I would then include that in my page,
> and add items to a PO by doing something like
> <?php
> include('pocode.php');
> $po = new PO();
>
> If($_POST['submit']=='Add'){
> //A HTML Button next to a text box to add a line item
> $po->AddItem('12345','5063');
> }
>
> $po->ListItems('12345');
>
> ?>
>
> Do I have the basic concept right? This is like relearning to code.
> Perhaps I learned in a bad way if that's the case. Any
> especially good
> tutorials or books to recommend?
>
> Thanks
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php