Re: PHP in general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The first
} should be after the last } for addRow() to be a method.. lol... Like this
(didn't try, but seems correct):

<html>
<head>
<title>A Class with a Constructor</title>
</head>
<body>
<?php

// Defining the Class's Properties -------
class Table
{
var $table_array = array();
var $headers = array();
var $cols;


//Creating a Constructor ------
function Table( $headers )
 {
 $this->headers = $headers;
 $this->cols = count ( $headers );
 }

//The addROw() Method ------
function addRow( $row )
 {
 if ( count ($row) != $this->cols )
  return false;
 array_push($this->table_array, $row);
 return true;
 }

//The addRowAssocArray() Method
function addRowAssocArray( $row_assoc )
 {
 $row = array();
 foreach ( $this->headers as $header )
  {
  if ( ! isset( $row_assoc[$header] ))
   $row_assoc[$header] = "";
  $row[] = $row_assoc[$header];
  }
 array_push($this->table_array, $row);
 return true;
 }

//
function output()
 {
 print "<pre>";
 foreach ( $this->headers as $header )
  print "<B>$header</B>  ";
 print "\n";
 foreach ( $this->table_array as $y )
 {
  foreach ( $y as $xcell )
  print "$xcell  ";
 print "\n";
 }
 print "</pre>";
 }
}
$test = new table( array("a", "b", "c") );
$test->addRow( array(1,2,3) );
$test->addRow( array(4,5,6) );
$test->addRowAssocArray (array ( b=>0, a=>6, c=>3 ) );
$test->output();
?>
</body>
</html>


-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
##########################
Please, if you are using windows, you may be infected by Swen. Please go
here to find out more:
http://us.mcafee.com/virusInfo/default.asp?id=helpCenter&hcName=swen
http://securityresponse.symantec.com/avcenter/venc/data/w32.swen.a@mm.html
##########################
"Rocco Castoro" <roccoman@tampabay.rr.com> skrev i meddelandet
20031116011631.22011.qmail@pb1.pair.com">news:20031116011631.22011.qmail@pb1.pair.com...
> ok, this is gunna be annoying but does anyone know why i get this error:
> Fatal error: Call to undefined function: addrow() in C:\Program
Files\Apache
> Group\Apache2\htdocs\Hour8-7MainExample.php on line 63 when trying to
> execute this code:
>
> <html>
> <head>
> <title>A Class with a Constructor</title>
> </head>
> <body>
> <?php
>
> // Defining the Class's Properties -------
> class Table
> {
> var $table_array = array();
> var $headers = array();
> var $cols;
> }
>
> //Creating a Constructor ------
> function Table( $headers )
>  {
>  $this->headers = $headers;
>  $this->cols = count ( $headers );
>  }
>
> //The addROw() Method ------
> function addRow( $row )
>  {
>  if ( count ($row) != $this->cols )
>   return false;
>  array_push($this->table_array, $row);
>  return true;
>  }
>
> //The addRowAssocArray() Method
> function addRowAssocArray( $row_assoc )
>  {
>  $row = array();
>  foreach ( $this->headers as $header )
>   {
>   if ( ! isset( $row_assoc[$header] ))
>    $row_assoc[$header] = "";
>   $row[] = $row_assoc[$header];
>   }
>  array_push($this->table_array, $row);
>  return true;
>  }
>
> //
> function output()
>  {
>  print "<pre>";
>  foreach ( $this->headers as $header )
>   print "<B>$header</B>  ";
>  print "\n";
>  foreach ( $this->table_array as $y )
>  {
>   foreach ( $y as $xcell )
>   print "$xcell  ";
>  print "\n";
>  }
>  print "</pre>";
>  }
>
> $test = new table( array("a", "b", "c") );
> $test->addRow( array(1,2,3) );
> $test->addRow( array(4,5,6) );
> $test->addRowAssocArray (array ( b=>0, a=>6, c=>3 ) );
> $test->output();
> ?>
> </body>
> </html>
>
> thanks
> "Rocco Castoro" <roccoman@tampabay.rr.com> wrote in message
> 20031116011115.15724.qmail@pb1.pair.com">news:20031116011115.15724.qmail@pb1.pair.com...
> > Yes it does, But IM lost in a space full of variables and strings and I
> dont
> > know what half of them mean, I dont wanna give up but this book
SUCKS....
> > "Gaguwd" <larenga2985@yahoo.com.ar> wrote in message
> > PAEKIBPEBDMPALHFKNCKIEGECMAA.larenga2985@yahoo.com.ar">news:PAEKIBPEBDMPALHFKNCKIEGECMAA.larenga2985@yahoo.com.ar...
> > > Wellllllllll, it depends on what you want to make. PHP has almost no
> > limits.
> > > Since it works with FTP, MySQL and many other external languages,
> > protocols
> > > and the like, your imagination is the limit.
> > >
> > > So, it's used for many things. There are blog scripts, guestbooks,
> > counters,
> > > database managers, portal managers, forum managers, email systems, RPG
> > > games, and lots of etc.
> > >
> > > Hope it helps...
> > >
> > > Bye!
> > > MG29
> > >
> > > -----Mensaje original-----
> > > De: Rocco CAstoro [mailto:roccoman@tampabay.rr.com]
> > > Enviado el: Sábado, 15 de Noviembre de 2003 09:14 p.m.
> > > Para: php-windows@lists.php.net
> > > Asunto:  PHP in general
> > >
> > >
> > > I'm learning PHP for reasons I dont know... I just feel that with my
> > passion
> > > for code and computers, that I will be able to use this information to
> > > create great things... I guess my question is, what all is PHP used
for
> > > anyways?
> > >
> > > --
> > > PHP Windows Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux