RE: Help with array in class needed
| From: | ArsenKirillov | Date: | Sun, 11 Nov 2001 23:15:53 +0000 |
| Subject: | RE: Help with array in class needed | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74193@lists.php.net to get a copy of this message | ||
AK>but when I try to copy the array outside the class using a function that
AK>only does a return $this->$data, I only get one sub-array of the
AK>whole one.
AK>
AK>Any ideas?
AK>
AK>Thanks
AK>
AK>Alexander
AK>
AK>Code:
AK>
AK>class Adressen {
AK> var $connect; // database-handle
AK> var $daten = array(); // array for data
AK>
AK> // Constructor
AK> function Adressen($datenbank) {
AK> $this->$connect = $datenbank->getConnect();
Be carefull :-)
$this->connect = $datenbank->getConnect();
AK> }
AK>
AK> // read data from database
AK> function readData() {
AK> $this->$daten = array();
AK> $result = mysql_query("select * from adressen");
AK> while($data = mysql_fetch_array($result)) {
AK> extract($data);
AK> $this->$daten[$AdressenID] = array("strasse" => $Strasse,
AK>"plz" => $PLZ,
AK>"ort" => $Ort, "land" => $Land, "telefon" => $Telefon,
AK>"telefax" =>
AK>$Telefax, "email" => $Email);
AK> }
AK> }
AK>
AK> function getData() {
AK> return $this->$daten;
Be carefull :-))
AK> return $this->daten;
AK> }
AK>}
AK>
AK>
AK>
-------------------------------------------- Here is working sanple is u are
losen again
<?
/*I've written a class that reads a database into an array. This works fine,
but when I try to copy the array outside the class using a function that
only does a return $this->$data, I only get one sub-array of the whole one.
Any ideas?
Thanks
Alexander
Code:
*/
class Adressen {
var $conn_ect; // database-handle
var $daten; // array for data
// Constructor
function Adressen($datenbank)
{
$it=$datenbank->getConnect();
echo $this->connect = $it;
// $result = mysql_query("select * from mysql.db");
// if (!$result){echo "false result !";exit();}
// print_r( $result );
}
// read data from database
function readData()
{
echo $this->connect;
$this->$daten = array();
$result = mysql_query("select * from mysql.db");
while($data = mysql_fetch_array($result))
{
extract($data);
$this->daten[$Db] = array("database" => $Db, "host_name" =>
$Host);
echo $Db." - ".$Host," <br>";
echo $j++."<br>";
}
}
function getData()
{
return $this->daten;
}
}
class MySQL
{
var $con_id;
function MySQL($host="localhost")
{
$this->con_id=mysql_connect($host);
}
function getConnect()
{
return $this->con_id;
}
}
$mydb=new MySQL;
$adr =new Adressen($mydb);
$adr->readData();
echo "<pre>";
print_r($adr->getData());
echo "</pre>";
?>