Re: Class results conflict with non-class code

From: Date: Fri, 20 Oct 2000 22:21:06 +0000
Subject: Re: Class results conflict with non-class code
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-21497@lists.php.net to get a copy of this message
Darrell Brogdon wrote: > > I have the following script that, when run, provides conflicting > results. In TEST 1 I never get any response because it goes into a > never-ending loop. That's because you re-query each iteration of the loop in the first case. Spend a few minutes comparing your code and the problem will leap out at you ;-). You probably want to put your query stuff in the constructor and use the fetch call in the getOptions method instead of in the while loop. > However, if I run the same code but without the > class as in TEST 2 it works perfectly. That's cuz it's not the same code. Ciao, Andreas > Is there a work-around for this > or have I discovered a bug? > > Please send responses directly to my email address if possible as I'm > not subscribe to the php-general list. > > ----- CODE SNIPPET --------- > > <?php > // TEST 1 BEGIN > class tester { > function tester() > { > mysql_pconnect("localhost", "foo", "bar"); > mysql_select_db("foobar"); > } > > function getOptions($foo_id) > { > $query = "SELECT * FROM foo WHERE foo_id='$foo_id'"; > $res = mysql_query($query); > > return $res; > } > } > > $test = new tester(); > > while( $options = mysql_fetch_array($test->getOptions("1")) ) { > print("$x: " . $options["foo_id"] . "<br>\n"); > print("$x: " . $options["foo_option"] . "<br>\n"); > } > // TEST 1 END > > // TEST 2 BEGIN > $query = "SELECT * FROM foo WHERE foo_id='1'"; > $res = mysql_query($query); > > while( $row = mysql_fetch_array($res) ) { > print("$x: " . $row["foo_id"] . "<br>\n"); > print("$x: " . $row["foo_option"] . "<br>\n"); > } > // TEST 2 END > ?> > -- Ciao, Andreas Pour http://www.kde.com/ : Everything KDE http://apps.kde.com/: The Latest in KDE Applications

« previous php.general (#21497) next »