...

View Full Version : Resolved sql array results



sitNsmile
03-29-2010, 05:06 PM
I've only been able to get this to show one game from the database, but I like it to display 5 games, I've tried "while" statement and yet that comes back false

limit = 5 (I want to show 5 results) this code is outputting only 1 result.



$sql = "SELECT * FROM games_info LIMIT 5";
$runSql = $dbBroker->arcade->fetchAll($sql);

foreach($runSql as $game)
{
print_r($game);echo "<br />";
}



Thanks for anyone that can help me get the array function to work properly.

abduraooft
03-29-2010, 05:17 PM
Could you please post the function fetchAll()?

sitNsmile
03-29-2010, 05:19 PM
Could you please post the function fetchAll()?


Right now i've got (includes built in APC cache)





public function fetchAll($query,$ttl = 0,$resultmode = null){

if($ttl > 0){

$key = md5($query);
if(!$result = apc_fetch($key)){
$result = parent::query($query,$resultmode)->fetch_object();
apc_store($key,$result,$ttl);
}

return $result;
}

//return parent::query($query,$resultmode)->fetch_object();
if($return = parent::query($query,$resultmode)){
return $return->fetch_object();
}else{
return array();
}

}

Fou-Lu
03-29-2010, 08:27 PM
FetchAll's job appears to be to fetch each of the columns, not the rows.
MySQLi has a builtin method called fetch_all. If you use that one, $resultmode will have to be given a valid default. That will take more memory though compared to the while fetch. The end result should be about the same memory usage.

sitNsmile
03-29-2010, 08:34 PM
Yeah thanks, actually deceided to build another function to handle with the array method.


private function _buildArray(mysqli_result $result)

so far things have come along okay. ;)

Thanks for input!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum