Page 1 of 1

Storing Array of dropdown box into table

Posted: Tue Apr 12, 2005 3:55 pm
by brendonknoetze
Hi
You guys helped me solve a problem before, and I was hoping that you might be able to help me with the following. I have an for loop that creates a list of drop down boxes and checkboxes.
The list is changeable hence why i had to do this.

Code: Select all

$linkID = mysql_connect("localhost", "root", "durban12");
	  mysql_select_db("talent", $linkID);
	  
	  $resultID = mysql_query("SELECT fun_list_id, fun_list_name, fun_checkbox
	  							FROM function_list where fun_list_active = '1'", $linkID);
	  
	  		$row = mysql_fetch_assoc($resultID);
		
		print "<font face='Arial, Helvetica, sans-serif'> <table border=\"1\"><tr><th><font size='1' >Function ID</th>";
		print "<th><font size='1'>Functional Experience</th>";
		print "<th><font size='1'>Year Exp.</th>";
		print "<th><font size='1'>Core</th></tr>";

		for ($x = 0; $x <mysql_num_rows($resultID); $x++)
		{
			$row = mysql_fetch_assoc($resultID);
			
			print "<tr>";
			print "<td><font size='1'>" . $row[fun_list_id] ."</td>";
			print "<td><font size='1'>" . $row[fun_list_name] ."</td>";
			print "<td><font size='1'> <select name='select".$row[fun_list_id]."'>
        					<option value='0'>None</option>
							<option value='1'><6 months</option>
       						<option value='2'>6-12 months</option>
        					<option value='3'>18 months</option>
        					<option value='4'>2-3 years</option>
        					<option value='5'>3-4 years</option>
        					<option value='6'>>5 years</option>
      					</select>";
			print "<td> <input type='checkbox' name='checkbox".$row[fun_list_id]."'/></td>";						
			print "</tr>";
		} //close for loop
		print "</font></table>";
	  mysql_close($linkID);
How do I create the sql update (or insert) query that accepts these changed variable names.

Many thanks in advance.

Brendon

Posted: Thu Apr 14, 2005 5:53 pm
by feyd
  1. remember to quote your string literals.
  2. your form process will have to search for the fields "name<your id thing>" .. although I'd suggest renaming them so they create an array automatically in php, so you can simply iterate over it. I've suggested this many times before.. hint hint.