Re: class method

From: Date: Tue, 20 Mar 2001 23:43:03 +0000
Subject: Re: class method
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-7664@lists.php.net to get a copy of this message
Yeah, the var $query is defined to the class. I did mistype the result, thanks. I was able to make this bad boy work with placing $field = $row['row_name']; // whatever the row is called. But, if that is the case, why would I need a class? I am just trying to make it so that I can use the loop for any query that needs it, and can show any row when I need it. I appreciate your help! Thanks a lot bryan ----- Original Message ----- From: "JJeffman" <jjeffmanweb@conex.com.br> To: "db" <php-db@lists.php.net> Sent: Tuesday, March 20, 2001 1:46 PM Subject: Re: [PHP-DB] class method > 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 ] > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#7664) next »