You will probably want to use AJAX and php to do this....
First, if you don't have a jquery library, you can get it at http://jquery.com/download/
This will enable you to use AJAX jquery.
In your html header:
<script>
$(document).ready(function() {
$("#category").change(function() {
var selectVal = $('#category :selected').text();
$.ajax({
url: 'getsubcat.php',
data: "groupid="+selectVal,
type:'post',
//dataType: 'json',
success: function(data)
{
$('#subcat').html('<option value="">'+data+'</option>');
}
});
});
});
</script>
In the html body --
<?php
include('conn.php');
$sql = "SELECT * FROM categories";
$result3 = pg_query($con, $sql);
?>
<!-- first select list -->
Select a category: </td><td>
<select id="category" name="category">
<option value = ""></option>
<?php
while($row = pg_fetch_array($result3)) {
echo '<option >'.$row[1].'</option>';
}
?>
</select>
<?php
$sql = "SELECT * FROM subcategories where cat = '$cat'";
$result3 = pg_query($con, $sql);
?>
Select a sub category:
<select id="subcat" name="subcat">
<option value = ""></option>
<?php
while($row = pg_fetch_array($result3)) {
echo '<option>'.$row[1].'</option>';
}
?>
</select>
Finally, in your php file -- getsubcat.php
<?php
$category = $_POST['groupid'];
include('conn.php');
$sql="select * from subcat where cat_name = '$category'";
$result = pg_query($con, $sql);
while($row = pg_fetch_array($result)) {
echo '<option>'.$row[1].'</option>';
}
pg_query($sql) or die("Error: ".pg_last_error());
?>
All of this will allow you to have your select lists dynamic an dependent on the first one.
Here I am using postgresql for the database, but you should be able to change the connection string (conn.php) and the table names, columns if you are using a different database like mysql.