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

     }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.