bradkenyon Posted February 28, 2007 Share Posted February 28, 2007 i have a form, in which i want to submit the results into a table. each answer will go into its own cell within the table. each question's name is q#, going from q0 to q49. there has to be where i can run something so i goes thru each one and posts q0 to column q0 within the db table, q1 to q1 column, so on and so forth. is that do-able? if so, what would it look like im thinking something like (excuse my crewd theory below): while(it starts at q0 and it hasn't come to q49 yet, do this) { each time i run, add to it, to count that cycle post[$q#] to table column[$q#]; } for example: <tr bgcolor="#ECF1EF"> <td width="41%">Printing</td> <td width="23%"><input name="q6" type="radio" value="Yes"> Yes </td> <td width="36%"><input name="q6" type="radio" value="No"> No </td> </tr> <tr> <td>Dispensing</td> <td><input name="q7" type="radio" value="Yes"> Yes</td> <td><input name="q7" type="radio" value="No"> No</td> </tr> <tr bgcolor="#ECF1EF"> <td>Wire</td> <td><input name="q8" type="radio" value="Yes"> Yes </td> <td><input name="q8" type="radio" value="No"> No</td> </tr> <tr> <td>Preforms</td> <td><input name="q9" type="radio" value="Yes"> Yes </td> <td><input name="q9" type="radio" value="No"> No</td> </tr> Link to comment https://forums.phpfreaks.com/topic/40601-submitting-form-results-into-a-db-table/ Share on other sites More sharing options...
boo_lolly Posted February 28, 2007 Share Posted February 28, 2007 i assume something like this would work: <?php $cols_array = array("column1", "column2", "column3", "column4", "column5"); if(isset($_POST)){ $cols = implode(", ", $cols_array); $values = implode(", ", $_POST); $sql = "INSERT INTO your_table (". $cols .") VALUES (". $values .")"; mysql_query($sql) OR die(mysql_error()); } ?> Link to comment https://forums.phpfreaks.com/topic/40601-submitting-form-results-into-a-db-table/#findComment-196423 Share on other sites More sharing options...
jwk811 Posted February 28, 2007 Share Posted February 28, 2007 maybe you are looking for the for loop? for(i=0, i < 49, i++){ $_POST whatever your trying to do } Link to comment https://forums.phpfreaks.com/topic/40601-submitting-form-results-into-a-db-table/#findComment-196424 Share on other sites More sharing options...
boo_lolly Posted February 28, 2007 Share Posted February 28, 2007 maybe you are looking for the for loop? for(i=0, i < 49, i++){ $_POST whatever your trying to do } i first thought of that, but that would be much slower and take up more resources if he inserted a different value in a different cell for every input field. it's much better just to use one query and get it over with. it would be like doing the same amount of damage with a gattlin gun, as opposed to using a grenade =). Link to comment https://forums.phpfreaks.com/topic/40601-submitting-form-results-into-a-db-table/#findComment-196427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.