In Reply to:
>Hello all.
>I have a question.
>How can i define some flexible variables?

You would have to have a method in your object that echoed passed variable
names.  So it would look like this instead:

echo $obj->write(ID);
echo $obj->write(TOWN);
echo $obj->write(PHONE);

Or create an array within your object that contains your result set, then it
could look like this:

echo $obj->data[ID];
echo $obj->data[TOWN];
echo $obj->data[PHONE];

It would probably be better as a 2-dim array actually like this:

echo $obj->data[$i][ID];
echo $obj->data[$i][TOWN];
echo $obj->data[$i][PHONE];

That way you would know what row to fetch from the database, and could cycle
through the results.

I think the way it should be done from an OOP design perspective is:

echo $obj->write($i, ID);
echo $obj->write($i, TOWN);
echo $obj->write($i, PHONE);

Because the value of properties should only be accessed by and objects
methods.  Programming references like:

echo $obj->variable_name;

Should really be:

echo $obj->someMethod(variable_name);

that returns the desired information.

Regardless I don't see how you can do what you want with an object.  You
have to declare all of your variable (property) names at the begining of the
object's definition, so they really can't be variable.  Use an array, or a
seperate method.

I suppose you might be able to have the constructor handle variable names
that you pass, but it still would not look like your example, and would
require that you create a new object everytime.

I probably just made things more confusing.  If you really need help, repost
with more info and I'm sure you will find help.

Robert Zwink

-----Original Message-----
From: Mircea Romanitan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 20, 2001 11:42 AM
Subject: [PHP-DB] flexible variables

Hello all.

I have a question.
How can i define some flexible variables?

Suppose i have a table with (id, town, phone).
In a file i have

define ("ID", "id");
define ("TOWN", "town");
define ("PHONE", "phone");

and after i send a query( SELECT * FROM table) to that db and got the query
into an object,
i need to write:

echo $obj->ID;
echo $obj->TOWN;
echo $obj->PHONE;

 but i cannot figure how?
I tried to use variable variables, but it don't work.


PHP Database Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to