my php problem

Posted on Sunday 15th June 2008 at 07:14 AM
Matt
Matt's Avatar
i'm having a problem right now, and the reason is because i'm not fully understanding how i'm suppossed to do this.

i have a page where an admin can add a poll, the poll system uses 3 mysql tables, poll, questions, responses. i will show a link to an online demo:
https://dev64.frankychan04.com/cms/?page=polls&a=3
you enter the name for the poll, then you enter the amount of options you want, the amount of options can be unlimited.
the query to create the poll is done after the first step, now i want to know is how to load every option into the table, what would my query look like, and what would the for loop look like, thanks.
Posted on Sunday 15th June 2008 at 06:20 PM
Adam981
Adam981's Avatar
it would help if we seen the php codes, use [php*] php code here [/php*] without the stars
Posted on Sunday 15th June 2008 at 06:30 PM
Matt
Matt's Avatar
PHP Code
  1. <?php
  2. //-----------------------------------------------------------------
  3. // Create Poll
  4. //-----------------------------------------------------------------
  5.  
  6. case 3:
  7.  
  8. if ($_POST['question'] && $_POST['options'])
  9. {
  10. //-----------------------------------------------------------------
  11. // Insert the poll
  12. //-----------------------------------------------------------------
  13.  
  14. $db->insertRow("poll",array('name' => ''.$_POST['question'].'','user' => ''.$userinfo['username'].'','date' => ''.time().''));
  15.  
  16.  
  17. if ($_POST['options'])
  18. {
  19.  
  20. //-----------------------------------------------------------------
  21. // Add in the options
  22. //-----------------------------------------------------------------
  23.  
  24. startbox("Step Two");
  25. $options = $_POST[options];
  26. echo "<form action='$PHP_SELF?page=polls&a=3' method='post'><table class='main' cellspacing='1' cellpadding='5'>";
  27. for ($a = 1; $a <= $options; $a++)
  28. {
  29. echo '<tr class="con1"><td>Option '.$a.': <input type="text" value="'.$a.'" /></td></tr>';
  30. }
  31.  
  32. ?>
  33.  
  34. </table><br/>
  35. <table class="main" cellspacing="1" cellpadding="3">
  36. <tr class="con1">
  37. <td width="50%">Actions:</td>
  38. <td width="50%" align="right"><input type="submit" value="Next &raquo;" /></td>
  39. </tr>
  40. </table></form>
  41.  
  42. <?php
  43.  
  44. } else {
  45.  
  46. //-----------------------------------------------------------------
  47. // This is the part i can't figure out
  48. //-----------------------------------------------------------------
  49.  
  50.  
  51. } else {
  52.  
  53. ?>
  54.  
  55. <div class="box">
  56. <div class="boxtitle"><?=$language['Poll add title']; ?></div>
  57. <div class="boxcontent">
  58. <form action="<?=$PHP_SELF;?>?page=polls&a=3" method="post">
  59. <table class="main" cellspacing="1" cellpadding="5">
  60. <tr class="head">
  61. <td width="70%"><?=$language['Poll add desc']; ?></td>
  62. <td width="10%" align="center"><?=$language['Poll add desc3']; ?></td>
  63. </tr>
  64. <tr class='con1'>
  65. <td>
  66. <input type="text" name="question" class="box" style="width:100%;" size="65" value="" />
  67. </td>
  68. <td align="center">
  69. <input type="text" class="box" name="options" style="width:30px;" />
  70. </td>
  71. </tr>
  72. </table>
  73. </div></div><br/>
  74. <table class="main" cellspacing="1" cellpadding="3">
  75. <tr class="con1">
  76. <td width="50%">Actions:</td>
  77. <td width="50%" align="right"><input type="submit" value="Next &raquo;" /></td>
  78. </tr>
  79. </table></form>
  80.  
  81. <?php
  82.  
  83. }
  84.  
  85. break;
  86. ?>


for each option there is, i want each option added into my database, that is the query and for loop i can't figure out.
Posted on Sunday 15th June 2008 at 07:09 PM
Adam981
Adam981's Avatar
Hmm you have a different kinda poll then im use too, id say msg MOD-Shadow, he might be able to help. unless u wanted to use the poll we hve here.
Posted on Sunday 15th June 2008 at 07:14 PM
Matt
Matt's Avatar
thats when it comes to adding the poll.
PHP Code
  1. for ($a = 1; $a <= $options; $a++)
  2. {
  3. echo '<tr class="con1"><td>Option '.$a.': <input type="text" value="'.$a.'" /></td></tr>';
  4. }


Say i have 5 options, all 5 options are generated with that code, so for each option i have, i want a row created in the database, how would i do that?
Login or register to respond to this forum topic.