function doSelect($theID, $level) {
# Standard connection code. To be moved into a seperate function or
# include file soon
$conn = mysql_connect("localhost", "x", "x") or die ("Couldn't connect: " . mysql_error());
mysql_select_db("x") or die("Couldn't select database: " . mysql_error());
# MID is the 'master ID', or the person/location owning the truck.
# 'disname' is the displayed name for internal purposes. There is a
# longer proper name in each record that is used to pretty up invoices we
# generate. 'active' is an ENUM indicating current clients (old ones we
# don't use anymore are set to 'no')
$sql = "SELECT * FROM dat_clients WHERE (MID = '$theID' AND active = 'yes') ORDER BY 'disname'";
$result = mysql_query("$sql") or die ("Couldn't query: " . mysql_error());
# this string is used to indent options in the select box. I think
# building it via loop here is expensive. Don't know how to do it like
# perl's "A" x <integer> method?
$pushin = "";
$x = 0;
while ($x < $level) {
$pushin = $pushin . " ";
$x = $x + 1;
}
# Found a parent, so do a recursion to get children-parents. Could be
# prettier. Would like to indicate a style or something to bold a
# 'parent', but this will do for now
while ($row = mysql_fetch_assoc($result)) {
$levelstring = $levelstring . " ";
echo "<OPTION CLASS=\"master\" VALUE=\"" . $row['ID'] . "\">" . $pushin . $row['disname'] . "\n";
doSelect($row['ID'], $level+1);
}
}