I'm constructing a drop down menu that has two sets of returns on a sql query for the value(s) from two different tables. The tables are :
TABLE1
------------------------
id | deptID | name
------------------------
1 | 1 | Group 1
2 | 1 | Group 2
3 | 2 | Group 3
4 | 2 | Group 4
5 | 3 | Group 5
------------------------
TABLE2
-------------------
id | name
-------------------
1 | Department 1
2 | Department 2
3 | Department 3
-------------------
... and my PHP query is here :
$sql = "SELECT * FROM table1 RIGHT JOIN table2 ON (table1.deptID = table2.id) ORDER BY table1.id ASC";
$result = @mysql_query($trace, $connect) or die(mysql_error());
$input_box = "
<select name=groups>
<option>Select One</option>
<option>-------------------------------------------</option>
";
while ($row = mysql_fetch_array($result)) {
$input_box .= '<option value="' . $row['table1.id'] . ',' . $row['table1.deptID'] . '"';
if (($row['table1.id'] == $_POST[groups]) && ($row['table1.deptID'] == $_POST[groups])) {
$input_box .= ' selected';
}
$input_box .= '>' . $row['table2.name'] . ' - ' . $row['table1.name'] . '</option>';
}
$input_box .= "</select>";
This works - the resulting value when I select one of the options shows the select box's value as $table1.id,$table1.deptID (or, for example, "1,1", or "2,1", or "3,5").
Now, what I'd like to do is to take that value and figure out a method by which I can separate those two results (numbers) into two totally separate variables so I can construct an INSERT query for separate fields for each value. I don't really know where to start on how to do that, so if anyone has any advice I'd really appreciate it.