TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-12-2010, 11:09 PM   #1 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default 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

Last edited by pipesportugal : 06-12-2010 at 11:21 PM. Reason: mistake
pipesportugal is offline  
Reply With Quote
Old 06-13-2010, 07:00 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by pipesportugal View Post
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."
__________________

Village Idiot is offline  
Reply With Quote
Old 06-13-2010, 09:19 PM   #3 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default

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

Last edited by pipesportugal : 06-13-2010 at 09:21 PM. Reason: mistake
pipesportugal is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
base classes..... allworknoplay Absolute Beginners 16 05-10-2009 08:09 PM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 09:26 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design