Thread: help with oop
View Single Post
Old 10-06-2008, 03:39 PM   #2 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Ok, one or two things wrong with the class.

PHP Code:
$output mysql_query($this->query=$in_query)or die(mysql_error());
return 
$output
Pointless variable, just uses up memory albeit not alot but it all adds up:
PHP Code:
return mysql_query($this->query=$in_query)or die(mysql_error()); 
Would produce the same effect.

Also:
PHP Code:
function fetch($this->query($in_query),$field)) {

while(
$row mysql_fetch_assoc($this->query($in_query)) {


echo 
$row['$field'];

You cant do that within function parameters and also if it did work, it would be useless as you call the same function within the body of the function.

Also each time your while loop loops, you are calling a query and getting a new resource, which will loop infinitely over the top entry in the table.
This will accomplish the same thing without looping infinitely
PHP Code:
    function fetch($in_query$field) {
        
$res $this->query($in_query);
        while(
$row mysql_fetch_assoc($res)) {
            echo 
$row[$field] ;
        }
    } 
As to your actual question, do you mean something like this:
PHP Code:
    function fetch($in_query) {
        
$res $this->query($in_query);
        
$retArr = array();
        while(
$row mysql_fetch_assoc($res)) {
            
$retArr[] = $row;
        }
    return 
$retArr;
    } 
That fetches all the rows from the result set.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote