•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,665 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,876 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 232 | Replies: 7 | Solved
![]() |
•
•
Join Date: Oct 2006
Posts: 88
Reputation:
Rep Power: 2
Solved Threads: 0
I'm trying to create a webpage where by I have the questions in the database instead of it being hard code which is writing it down in php. How do i go about that. Just a simple page which will have a question and a blank box where the answer is meant to be written and the answer would also be stored in the database. Please any help would be really appreciated. I hope you understand what i'm trying to say
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
Simple. Fetch all the questions from the table and print it as follows.
When the user clicks on submit, get the value of i, loop through the answers.
cheers,
Naveen
php Syntax (Toggle Plain Text)
$query="Select question from question_table"; $result=mysql_query($query); $i=1; echo "<form method=\"post\" action=\"questionpaper.php\">"; while($row=mysql_fetch_array($result)){ $question=$row['question']; echo $i."." $question."<br />"; // to print 1. What is your name ? echo "<input type=\"text\" name=\"answer$i\" /><br />"; \\ to have unique textboxes for different questions $i++; } echo "<input type=\"hidden\" name=\"count\" value=\"$i\">"; \\ to count the number of questions echo "<input type=\"submit\" name=\"submit\" value=\"submit\">"; ?>
php Syntax (Toggle Plain Text)
$i=$_REQUEST['count']; for($j=1;$j<$i;$j++){ $answertextbox="answer".$j; $answer=$_POST[$answertextbox]; //insert $answer to the table } //by the end of for loop, all the answers will be in the table. ?>
cheers,
Naveen
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
Create a table with all the questions. You need another table to store the answers. question_id would be the foreign key in answers table. If you are doing this question-answer script for multiple users, you need another table users, whose 'user_id' would be a foreign key for table answers.
So, questions table will have
1. question_id, primary key
2. question
Answer table will have
1. answer_id, primary key
2. question_id, foreign key from questions table
3. user_id, foreign key from users table
Users table
1. user_id , primary key
and the user details
So, questions table will have
1. question_id, primary key
2. question
Answer table will have
1. answer_id, primary key
2. question_id, foreign key from questions table
3. user_id, foreign key from users table
Users table
1. user_id , primary key
and the user details
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
umm.. The code that I have given you is just an example how you can do it. Change it as per your needs. List all the questions with a textbox(with different names).You may also need to save the question_ids to store it in the answer table. When the submit button is pressed, get all the answers and the question_id's (for that particular user) and save it in the table.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
You are welcome!
Its easy. Just keep trying.. You ll get it. Best of luck!
Its easy. Just keep trying.. You ll get it. Best of luck! Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- memory management in wndows 2000 (Windows NT / 2000 / XP / 2003)
- Need opinions on a database design (Database Design)
- VB6 & Access (user name, network printer, reminders) (Visual Basic 4 / 5 / 6)
- Urgent Help With a SQL Where statement (MS SQL)
- Storing dynamic form values in Arrays for display & insert (PHP)
- data-grabbing & mining - need script-help (PHP)
- HTML Form post to PHP? (PHP)
- Experienced C# .NET developer looking for offsite job! (Post your Resume)
Other Threads in the PHP Forum
- Previous Thread: redirect page timer
- Next Thread: time difference



Linear Mode