Lets start with the form that sends an array from some <select> elements
Code: Select all
<select name="d1[]">
<option value="Mark">Mark</option>
<option value="John">John</option>
<option value="Peter">Peter</option>
<option value="Paul">Paul</option>
</select>
<select name="d1[]">
<option value="Mark">Mark</option>
<option value="John">John</option>
<option value="Peter">Peter</option>
<option value="Paul">Paul</option>
</select>
Code: Select all
foreach ($_POST['d1] as $item) {
echo $item."<br>";
}Code: Select all
foreach ($_POST[$group] as $item) {
$result = mysql_query("SELECT * FROM people WHERE peoplename = '$item' ", $connect);//connect to the database here
$userData = mysql_fetch_array($result, MYSQL_ASSOC);
$occu = $userData['occupation'];
echo $item." is a ".$occu;
}
HOWEVER.. thats not what i want. what i want is a way that in the processed data all im given is the persons names but i want them grouped to their occupation. so if there were 20 names in the database and 4 occupations and ive got 6 <select> elements then when its processed it would list them out with all the carpenters first, then all the fishermen then all the lawyers.
My thought but i cant figure out how to make it work is that in that foreach loop i stick names and related occupations into a new array. then sort that array alphebetically by occupations then do another foreach loop displaying only the names