Skip to main content
Apr 30, 2007 8:03 AM UTC
Question

Dynamic PHP output

I'm writing a page that will allow users to input questions and answers and then display the questions and answers to users so they are able to do the quiz. I'm having trouble with a part of it where I want the quiz writer to be able to input how many questions are asked, I'm having trouble outputting the number of questions specified if that makes any sense. So in my maker page I've got the user specifying the number of questions = 4 and then on the actual quiz I want to output the 4 questions specified. It's kinda confusing, I'm just struggling with the whole dynamic output thing.
This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Inspiring
May 2, 2007 12:48 PM UTC
slowpoke115 wrote:
> I dont want random questions,

If you don't want random questions, leave out ORDER BY RAND(). The rest
of the query is the same.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
May 2, 2007 11:29 AM UTC
I dont want random questions, it will make the rest of my code really confusing. At the moment I have a code where the questions and answers are specified, a page where the question created is selected and the output page. All of the details are read/wrote to a database which holds the questions and answers.

I have no idea how to do this really as my php is based on a more complicated version of this: http://www.developingwebs.net/phpclass/phpquizpage.php

If the worse somes to the worse I'll either have a huge case statement for the number of questions specified or make the user write say.. 10 questions leaving none blank.
Translate
Inspiring
Apr 30, 2007 8:53 AM UTC
slowpoke115 wrote:
> I want the quiz writer to be
> able to input how many questions are asked, I'm having trouble outputting the
> number of questions specified if that makes any sense. So in my maker page I've
> got the user specifying the number of questions = 4 and then on the actual quiz
> I want to output the 4 questions specified.

I presume that you want the questions to be selected at random, so this
is the SQL query you need:

SELECT * FROM questions
ORDER BY RAND() LIMIT 4

Since the number of questions will be variable, you need to create a
runtime variable, so you enter this in the Advanced Recordset dialog box:

SELECT * FROM questions
ORDER BY RAND() LIMIT var1

If you're using DW 8.0.2 or CS3, define var1 as Numeric, and set its
runtime value to $_POST['numQuestions'] or $_GET['numQuestions'],
depending on whether you use POST or GET to pass the number of questions
to the page.

There must be no space between RAND and the parentheses.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate