TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   retreiving information from the class (http://www.talkphp.com/absolute-beginners/5447-retreiving-information-class.html)

pipesportugal 06-12-2010 11:09 PM

retreiving information from the class
 
PHP Code:

// class name is record
// number of records is 1.
// vector_fields is an array with the fieldnames in the table 
// The field names are like: code_customer, name_customer, and so on.

//*************************************
while ($row2 mysql_fetch_array($this->result_sql)) {
  for(
$j0$j<count($this->vector_fields); $j++) {
     
$firstpartstring $this->vector_fields[$j];
     
$stringfieldname 'scr_'.$firstpartstring;
     
$this->$stringfieldname $row2['$firstpartstring'];
  } 
// END of for
// END of while

//*************************************
// From the main program I want to retrieve the name of the customer with:
//  $customer = new record();
//  $customer_invoice = $customer->scr_name_customer; 

I am geting the following error:
Catchable fatal error: Object of class registo could not be converted to string in /home/vnhdpwxq/public_html/classes/classe_ler_registos.php on line 68

I believe it is because of the sentence:

PHP Code:

$this->$stringfieldname 

The program is not expecting the "$" on the stringfieldname variable.
What I really need is to make a $this->scr_name_customer.

Can someone help me overpass this problem?

I have completely run out of ideas.

Thanks in advance,
PP

Village Idiot 06-13-2010 07:00 PM

Quote:

Originally Posted by pipesportugal (Post 30659)
PHP Code:

// class name is record
// number of records is 1.
// vector_fields is an array with the fieldnames in the table 
// The field names are like: code_customer, name_customer, and so on.

//*************************************
while ($row2 mysql_fetch_array($this->result_sql)) {
  for(
$j0$j<count($this->vector_fields); $j++) {
     
$firstpartstring $this->vector_fields[$j];
     
$stringfieldname 'scr_'.$firstpartstring;
     
$this->$stringfieldname $row2['$firstpartstring'];
  } 
// END of for
// END of while

//*************************************
// From the main program I want to retrieve the name of the customer with:
//  $customer = new record();
//  $customer_invoice = $customer->scr_name_customer; 

I am geting the following error:
Catchable fatal error: Object of class registo could not be converted to string in /home/vnhdpwxq/public_html/classes/classe_ler_registos.php on line 68

I believe it is because of the sentence:

PHP Code:

$this->$stringfieldname 

The program is not expecting the "$" on the stringfieldname variable.
What I really need is to make a $this->scr_name_customer.

Can someone help me overpass this problem?

I have completely run out of ideas.

Thanks in advance,
PP

It should be
PHP Code:

$this->stringfieldname 

. I don't understand what you mean by "What I really need is to make a $this->scr_name_customer."

pipesportugal 06-13-2010 09:19 PM

Hi VI,

From the main program I want to the following:

$customer = new record();
$customer_name = $customer->scr_name_customer;
$customer_email = $customer->scr_email_customer;
$customer_phone = $customer->scr_tele_customer;
$customer_fax = $customer->scr_fax_customer;
$customer_vat = $customer->scr_vat_customer;


On the record class I retrieve one variable called stringfieldname when I wanted to have all the different fields of the table on different variable names such as scr_name_customer, scr_email_customer, etc....

That's why I was using the $this->$stringfieldname =..., I had this variable inside a cycle varying, obtaining this way $this->scr_name_customer=..., $this->scr_email_customer=..., $this->scr_tele_customer=..., etc

I also tried another way which was inside this cycle to have a variable called "fieldname" with the variable names (this->scr_name_customer, this->scr_email_customer, this->scr_tele_customer=... and then use:

$$fieldname=....

But also did not work
I hope this clears Your doubts VI, I really need some help here.
I am starting to think that it will not be possible because I tried so many things. I have spent many hours here already.

Thanks in advance,
PP


All times are GMT. The time now is 06:44 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0