SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Inserting a new poll in Mysql??
-
Feb 9, 2002, 01:19 #1
- Join Date
- Feb 2002
- Location
- Reykjavik, Iceland
- Posts
- 104
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Inserting a new poll in Mysql??
Would someone be nice to help me with this poll ? =)
I´m developing a little POll for my site
I´m done with the script that calculates and view the poll and the "vote" insert query and now i´m struggling with the NEW POLL query, how i insert a new poll in the database.
I have the poll in 3 tables
The questions itself are stored in a table called "poll_questions"
that contain
ID auto inchrement
writer_id
question
and another table for "possibilites"
ID
ID_question << this contains the id of the question
possibilites
And now i´m gonna see how one poll qould look like in this tables
The question is "Does this question mean i´m total idiot"?
and the possibilities are yes,no,you´re ok..
The poll_question
ID [6]
writer_id [0585] << whatever!
question [Does this question mean i´m total idiot]
and the possibilites table would be
ID [798]
ID_question [6]
possibilite [yes]
ID [799]
ID_question [6]
possibilite [no]
ID [800]
ID_question [6]
possibilite [you´re ok..]
I also have another table for answears but that is no need to show that..
And what query would i have to have to insert this new poll into this database?
In the form page would the input form that has the name "pollquiz" and the possibilities input boxes that are up to 5 has name name answear1,answear2,answear3,answear5
Could somone give me a taste of the code that would insert this new poll into this tables in database?
That would be greatly appreciate?
-
Feb 13, 2002, 16:27 #2
If I understand you correctly try this:
PHP Code:mysql_query("INSERT INTO poll_questions SET writer_id=$writer_id, question='$question'");
$ques_id = mysql_insert_id();
for ($i = 0; $i < sizeof($answear); $i++) {
mysql_query("INSERT INTO possibilites SET ID_question=$ques_id, possibilites='$answear[$i]'");
}
Hopes this helps.
Cheers.
Bookmarks