Jump to content

Database Function Only Displaying 1 Record


ShoeLace1291

Recommended Posts

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] . ' ';
	   
	   } 

     }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.