Re: [PHP-DB] Polls?
Well, you are gonna have to do two queries if you want a dynamic number of questions in each poll, unless you want to do something limited and have 10 to 20 columns for each poll and leave the questions not questioned null... IE: table poll pollid name descr question1 question2 question3 question4 question...20 Now this assumes that each question has the same set of potential answers, or this doesn't work. The two table polls + questions (or even three tables, polls, questions, answers) wouldn't kill your server: $x = mysql_query(select * from polls); $y = mysql_query(select * from questions); $z = mysql_query(select * from answers); Then just iterate through them all, put them in an array: $polls[$row[id]] = $row_from_db; $questions[$row[id]] = $row_from_db; $answers[$row[id]] = $row_from_db; Then just relate them. while(list($pollid,$row)=each($polls)) { print $row['name'].br.$row['descr'].br; reset($questions); while(list($qid,$ques)=each($questions)) { if ($ques[pid] != $pollid) continue; print ddQuestion. .$ques['question'].br; reset($answers); while(list($aid,$ans)=each($answers)) { if ($ques[pid] != $pollid) continue; print dd{$ans['answer']}br; } } } Now you have done everything you need to display all the polls in PHP and not in the DB. I have no clue why you'd want to do it this way, but if your MySQL server is that taxed, then this is how I'd do it -- put the processing on the web server. Peter On Fri, 8 Nov 2002, Leif K-Brooks wrote: The problem is, I need to make a page that shows all of the polls, and one query per poll would kill the server. Peter Beckman wrote: Use the dual table questions and answers suggestion before. Then just use a loop: $question = mysql_query(select * from questions where id={$this_question}); while ($r = mysql_fetch_array($question)) { $answers = mysql_query(select * from answers where qid={$r[id]}); while ($s = mysql_fetch_array($answers)) { print question input and labels; } } On Fri, 8 Nov 2002, Leif K-Brooks wrote: I'm working on a polling system, and I'm having a bit of a problem. I'm not sure how to store the questions. Storing them in a seperate table would require a query for each poll displayed - not good. I've also thought of storing them as a serialized array. Any thoughts on this? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ --- -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. --- Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Polls?
Use the dual table questions and answers suggestion before. Then just use a loop: $question = mysql_query(select * from questions where id={$this_question}); while ($r = mysql_fetch_array($question)) { $answers = mysql_query(select * from answers where qid={$r[id]}); while ($s = mysql_fetch_array($answers)) { print question input and labels; } } On Fri, 8 Nov 2002, Leif K-Brooks wrote: I'm working on a polling system, and I'm having a bit of a problem. I'm not sure how to store the questions. Storing them in a seperate table would require a query for each poll displayed - not good. I've also thought of storing them as a serialized array. Any thoughts on this? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Polls?
The problem is, I need to make a page that shows all of the polls, and one query per poll would kill the server. Peter Beckman wrote: Use the dual table questions and answers suggestion before. Then just use a loop: $question = mysql_query(select * from questions where id={$this_question}); while ($r = mysql_fetch_array($question)) { $answers = mysql_query(select * from answers where qid={$r[id]}); while ($s = mysql_fetch_array($answers)) { print question input and labels; } } On Fri, 8 Nov 2002, Leif K-Brooks wrote: I'm working on a polling system, and I'm having a bit of a problem. I'm not sure how to store the questions. Storing them in a seperate table would require a query for each poll displayed - not good. I've also thought of storing them as a serialized array. Any thoughts on this? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ --- -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.
Re: [PHP-DB] Polls?
Leif, off the wall...what if you have a table for question, identified with an unique ID, and another where you store the results? BTW: how are the questions? Yes/No, or multiple choices, or combination of these two styles? On Fri, 8 Nov 2002, Leif K-Brooks wrote: The problem is, I need to make a page that shows all of the polls, and one query per poll would kill the server. Peter Beckman wrote: Use the dual table questions and answers suggestion before. Then just use a loop: $question = mysql_query(select * from questions where id={$this_question}); while ($r = mysql_fetch_array($question)) { $answers = mysql_query(select * from answers where qid={$r[id]}); while ($s = mysql_fetch_array($answers)) { print question input and labels; } } On Fri, 8 Nov 2002, Leif K-Brooks wrote: I'm working on a polling system, and I'm having a bit of a problem. I'm not sure how to store the questions. Storing them in a seperate table would require a query for each poll displayed - not good. I've also thought of storing them as a serialized array. Any thoughts on this? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ --- -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Polls?
I'm working on a polling system, and I'm having a bit of a problem. I'm not sure how to store the questions. Storing them in a seperate table would require a query for each poll displayed - not good. I've also thought of storing them as a serialized array. Any thoughts on this? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Polls?
Thanks, but my problem is how to efficiently display a page with all of the polls with results. Also, I need a variable number of questions, which that tutorial doesn't provide. Thanks, though. Ignatius Reilly wrote: One possibility: table questions( questionID, question_text, ...) PRIMARY KEY( questionID) table answers( FK_questionID, individualID, answer_code, ...) PRIMARY KEY( FK_questionID, individualID) For very simple online polls, there is a nice tutorial in Devshed: http://www.devshed.com/Server_Side/PHP/PHPDemocracy HTH Ignatius - Original Message - From: Leif K-Brooks [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, November 08, 2002 8:15 AM Subject: [PHP-DB] Polls? I'm working on a polling system, and I'm having a bit of a problem. I'm not sure how to store the questions. Storing them in a seperate table would require a query for each poll displayed - not good. I've also thought of storing them as a serialized array. Any thoughts on this? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.