Re: class method

From: Date: Tue, 20 Mar 2001 21:46:30 +0000
Subject: Re: class method
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-7661@lists.php.net to get a copy of this message
I need a little more information to help you. Is the $query variable a global one ? Or is it a property of the class ( var $query; ) ? Why are you assigning the "mysql_fetch_array" function to a variable if call it is easier ? You have misplaced the "if $result" statement, the right position, I think , is : function getdata() { $this->sql = $query; $result = mysql_query($query); if( $result ) { // Check if $result is valid instead of NOT valid // $fetch = "mysql_fetch_array"; while ($row = mysql_fetch_array($result)) { $this->field = $row['$this->field']; } } else $this->error = mysql_error(); return; } HTH Jayme. www.conex.com.br/jjeffman/antispam.html -----Mensagem Original----- De: bryan <bryan@concept-factory.com> Para: db <php-db@lists.php.net> Enviada em: terça-feira, 20 de março de 2001 16:21 Assunto: [PHP-DB] class method I am really new working with classes. Some of the ideas I am getting, some I am not. I wrote this simple little class, with a connection method, and a method to loop through the data. I am not even sure if my code is write (for the loop), but I am having trouble displaying the data. My connection works fine, but my loop is jacked. Could anyone suggest or maybe correct a mistake (if you see any)? Just looking to see if I am started in the right direction, or if I have this all bass ackwards. I have no clue if this is even possible. I am looking to create a while loop for whatever query I run, and make each row equal to whatever field I put in. I have all variables defined within the scope of my class. Thanks for your help. Code : ******************************** function getdata() { $this->sql = $query; $result = mysql_query($query); $fetch = "mysql_fetch_array"; while ($row = $fetch($result)) { $this->field = $row['$this->field']; } if(!$result) { $this->error = mysql_error(); return; } } ****************************** End thanks!!! [ bryan fitch . programmer . bryan@concept-factory.com ]

« previous php.db (#7661) next »