I'm getting the following error:

Fatal error: Maximum execution time of 30 seconds exceeded in \SERVER_PATH\functions.php on line 19

(where SERVER_PATH is the actual path).

I can't work out where the code is going wrong though (presumably there must be something I need to change), can anyone see which bit is inefficient (I appreciate it shows the row number, I just can't work out what is wrong though)?

<?php


function db_result_to_array($result){
//---------------------------------------------------------------------
$res_array = array();

for ($count=0; $row = $result->fetch_assoc(); $count++) {
$res_array[$count]=$row;
}

return $res_array;
}
//---------------------------------------------------------------------


function get_dataset($server, $user, $password, $database, $query7) {
//---------------------------------------------------------------------
$db1 = new mysqli($server, $user, $password, $database);
$query1 = $query7;
$result1 = $db1->query($query1);
$num_results = $result1->num_rows;

$result8 = db_result_to_array($result1);
return $result8;

$db1->close();}
//---------------------------------------------------------------------


function get_sub_dataset($server, $user, $password, $database, $query7,$sub_field_id) {
//---------------------------------------------------------------------
$db1 = new mysqli($server, $user, $password, $database);
$query1 = $query7;
$result1 = $db1->query($query1);
$num_results = $result1->num_rows;

$result8 = db_result_to_array($result1);
return $result8;}
//---------------------------------------------------------------------



function drop_down($array_name,$field_id, $query_field_id, $field_name,$server_name,$user_name,$password,$database_name,$query_string,$row,$multiple=0,$query_s tring2=0,$sub_field_id=0) {
//-------------------------------------------------------------------------------------------------------------------------
$stat_array=get_dataset($server_name,$user_name,$password,$database_name,$query_string);

//echo "<select name=".$array_name." width='100%'>";

if(empty($multiple)) {

echo "<select name=".$array_name." width='100%'>";
if ($row[$field_id] == $thiscat[$query_field_id]) {}{echo "<option>None Selected</option>";}

foreach ($stat_array as $thiscat)
{
echo '<option value="' . $thiscat[$query_field_id] . '"';

if ($row[$field_id] == $thiscat[$query_field_id]) {echo ' selected';}

echo '>' . $thiscat[$field_name] . '</option>';
}

}

else {echo "<select multiple size =".$multiple." name=".$array_name." width='100%'>";

foreach ($stat_array as $thiscat)
{
echo '<option value="' . $thiscat[$query_field_id] . '"';

$list_box_array=get_sub_dataset($server_name,$user_name,$password,$database_name,$query_string2,$sub _field_id);

foreach ($list_box_array as $list_box_row)
{
if ($list_box_row[$sub_field_id] == $thiscat[$query_field_id]) {echo ' selected';}
}

echo '>' . $thiscat[$field_name] . '</option>';
}

}

echo "</select>";

$db1->close;

}
//-------------------------------------------------------------------------------------------------------------------------


function simple_drop_down($drop_down_name,$field_id,$field_name,$server_name, $user_name, $password, $database_name, $query_string, $none, $default_value) {
//-----------------------------------------------------------------------------------------------------------------------------------
echo "<select name=".$drop_down_name.">";
$stat_array=get_dataset($server_name, $user_name, $password, $database_name,$query_string);
if ($none == 1) {echo "<option>None Selected</option>";}
foreach ($stat_array as $thisstat){
echo "<option value=\"".$thisstat[$field_id]."\"";
if ($default_value == $thisstat[$field_id]) {echo ' selected';}
echo ">".$thisstat[$field_name]."</option>";
}
echo "</select>";
}
$db1->close;
//-----------------------------------------------------------------------------------------------------------------------------------

?>