ShoeLace1291 Posted September 16, 2007 Share Posted September 16, 2007 I have a database function that fetches the mysql records from a certain table. I have it displaying information in an array and then I return the array after every loop. My problem is, that since I use "return", the function only displays the first record and then the loop stops because of the return being there. When I change it from "return" to "echo", it displays all the records it should, but the array list displays at the top of the page. How would I use something like return or echo but only displays when the function is called? This is my code: function get_games(){ $query = mysql_query("SELECT gameID,gameTitle,gameDescription FROM games"); $numgames = mysql_num_rows($query); for ($i = 0; $i < $numgames; $i++){ while($fetch=mysql_fetch_array($query)){ $gameID=$fetch["gameID"]; $gameTitle=$fetch["gameTitle"]; $gameDescription=$fetch["gameDescription"]; $temps = array( 'GAMEID' => $gameID, 'GAMETITLE' => $gameTitle, 'GAMEDESC' => $gameDescription ); $file="themes/default/game_list.tpl"; $setgames = set_template($file, $temps); $game[$i] = $setgames; echo $game[$i] . ' '; } } Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 16, 2007 Share Posted September 16, 2007 Make the results go into an array, and then return that array. Quote Link to comment Share on other sites More sharing options...
ShoeLace1291 Posted September 16, 2007 Author Share Posted September 16, 2007 How would I do this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.