Jump to content

Trouble with a function within a function...


Recommended Posts

Hey guys, I'm having some trouble with this function (well, the function within the function really).

I need the function to echo out a random question from the designated table, this is working fine, but then I need a function within this function to pull out all the answer options and echo them into a dropdown menu.

The dropdown menu shows, but there is no data found within it, although there is definitely data contained in the table. I keep getting the error "Fatal error: Cannot redeclare options()". I've attempted to also do it using mysql_num_rows but that didn't work so I thought I would try something simpler...

 

Here's the code:

 

		function retrieveData($data){
		$$data = mysql_query('SELECT * FROM '.$data.' ORDER BY RAND()') or die(mysql_error());
		$counter = 0;
		while($row = mysql_fetch_array($$data)){
			$question[$counter] = $row['question'];
			$counter++;
		}
		function options($data){
			$i = 0;
			while($row = mysql_fetch_array($$data)){
			$answer[$i] = $row['answer'];
			$i++;
			}
			echo "<option value=\"".$answer[$i]."\">".$answer[$i]."</option>";
		}
		echo $question[0];
		echo "<select name=\"0\">";
		echo "<option value=\"0\">Please select an answer...</option>";
		echo options();
		echo "</select>";
		echo "<br/>";
		echo $question[1];
		echo "<select name=\"1\">";
		echo "<option value=\"0\">Please select an answer...</option>";
echo options();
		echo "</select>";
		echo "<br/>";
	}

 

Any help would be awesome :)

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.