First of all let's use the handy magic [php] tags this forum comes with, and see if we can't make it a bit more legible. While we're about it, let's also aim for a bit of consistency in our coding style, so that we don't lose track of where we are in which loops or branches. Rough and ready is no excuse for making things difficult for yourself (and everyone who's trying to help).
<?php
//create the sql statement
$sql = "SELECT *
FROM dcass_groups
GROUP BY 'dcass_group'";
What do you mean "Group by dcass_group"? There are no aggregate functions being used, so no reason for grouping. What are you trying to get, a list of the dcass_group values?
SELECT DISTINCT dcass_group from dcass_groups would do that. And if the name of the table means anything,
each dcass_group probably only appears once anyway, so the distinct isn't needed either.
//execute the sql statement
$result = mysql_query($sql, $conn)or die(mysql_error());
//will go through each row in the result set and display data
while($row=mysql_fetch_array($result))
{
//give a name to the fields
$team_id = $row['team_id'];
$dcass_group = $row['dcass_group'];
$team_name=$row['team_name'];
Studies have shown that two out of three variables are never used. Maybe you're wanting these for something else here.
if (isset($_POST['dcass_group']))
{
$group_options .="<option value=\"$dcass_group\" selected>$dcass_group</option>\n";
}
$group_options .="<option value=\"$dcass_group\">$dcass_group</option>\n";
Well, there's a problem right there; without the else the selected item will show up twice - once selected, once not.
}
//to get the teams relevant to the group
//
if (isset($_POST['finalsubmit']))
{
//do something here
}
else
{
if (isset($_POST['dcass_group']))
{
$sql = "SELECT *
FROM dcass_groups
WHERE dcass_group = '$_POST[dcass_group]'";
//execute the sql statement
$result = mysql_query($sql, $conn)or die(mysql_error());
$teams='<select name="team1">';
while($row=mysql_fetch_array($result))
{
// RETURN DETAILS OF THE COUNTRY CHOSEN
$teams.='<option value="'.$row[team_name].'">'.$row[team_name].'</option>';
}
$teams.='</select>';
}
if (isset($_POST['dcass_group']))
Hang on, didn't we just test this?
{
$sql = "SELECT *
FROM dcass_groups
WHERE dcass_group = '$_POST[dcass_group]'";
//execute the sql statement
$result = mysql_query($sql, $conn)or die(mysql_error());
$teams2='<select name="team2">';
while($row=mysql_fetch_array($result))
{
// RETURN DETAILS OF THE COUNTRY CHOSEN
$teams2.='<option value="'.$row[team_name].'">'.$row[team_name].'</option>';
}
$teams2.='</select>';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
...
<form name="form1" method="post" action="<?php echo $_SERVER[php_self];?>">
... Well, that won't work - it needs to be $_SERVER['PHP_SELF'] ....
<select name="dcass_group" onChange="java script:submitform();">
<option value=''>--- Select your Group ---</option>
<?print $group_options;?>
</select>
</td>
</tr>
<tr>
<td>Team 1</td>
<td><?php echo $teams;?></td>
</tr>
<tr>
<td>Team 2</td>
<td><?php echo $teams2;?></td>
</tr>
<tr>
....
</html>