loquela Posted August 15, 2009 Share Posted August 15, 2009 Hi there, I have the following form something like the one below. I am trying to figure out sql query that will insert the value of each select in the loop into a new row: Any help would be greatly appreciated! <form> <?php do { ?> <select name="name[]" id="name1"> <option value="">Select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <input type="hidden" name="question" value ="<?php echo $row_questions['question_id']; ?>" /> <?php } while ($row_questions = mysql_fetch_assoc($questions)); ?> <input type="hidden" name="user" value="Current user" /> <input type="submit" name="submit" id="submit" value="submit" /> </form> Cheers! Link to comment https://forums.phpfreaks.com/topic/170375-inserting-multiple-rows-from-array/ Share on other sites More sharing options...
loquela Posted August 16, 2009 Author Share Posted August 16, 2009 I thought I'd solved this but I hadan't! Any ideas anyone? Thanks in advance. S. Link to comment https://forums.phpfreaks.com/topic/170375-inserting-multiple-rows-from-array/#findComment-899299 Share on other sites More sharing options...
ignace Posted August 16, 2009 Share Posted August 16, 2009 <form> <?php while ($row_questions = mysql_fetch_assoc($questions)) { ?> <select name="name[<?php echo $row_questions['question_id']; ?>]"> <option value="">Select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <?php } ?> <input type="hidden" name="user" value="Current user" /> <input type="submit" name="submit" id="submit" value="submit" /> </form> You can now access every question using $_POST['name'][$row_questions['question_id']] like: $_POST['name'][1] $_POST['name'][2] $_POST['name'][3] .. Link to comment https://forums.phpfreaks.com/topic/170375-inserting-multiple-rows-from-array/#findComment-899353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.