Alright here are my fucntions, all in line. Should work just perfectly together. The database connections inside of them are correct, infact no errors are printed - I am presented with 100% nothingness.
/**
* Finds all subdepartments of $parent in $array
*
* @param array $array Array of deparments from departments_grab()
* @param int $parent dept_id of a parent departments
* @author Andrew West <burstroo@gmail.com>
* @since 1.0.0
* @return array Array of subdepartments
**/
function department_array($array, $parent)
{
$arr = array();
for ($i = 0; $i < count($array); $i++)
{
if ($array[$i]['dept_parent'] == $parent) {
$arr[] = $array[$i];
}
}
return $arr;
}
/**
* Gets all departments and puts them in an array
*
* @param string $sort Field to sort by
* @author Andrew West <burstroo@gmail.com>
* @since 1.0.0
* @return array Array of all existing departments to be passed to select_departments()
**/
function department_grab($sort = 'dept_name')
{
$departments = array();
$q = $this->db->query('SELECT dept_id, dept_name, dept_parent FROM ' . $this->pre . 'departments ORDER BY ' . $sort);
while ($d = $this->db->nqfetch($q))
{
$departments[] = $d;
}
return $departments;
}
/**
* Options for an HTML select box (all departments in correct order)
*
* @param array $array Array of departments
* @param int $select Option to set as selected (-1 for all)
* @param int $parent Used to degredate down through the recursive loop
* @param string $space Used to increment the spacing before the text in the box
* @param bool $identify_category Set to true to place a period before the value of a category
* @author Andrew West <burstroo@gmail.com>
* @since 1.0.0
* @return string Options for an HTML select box (all departments in correct order)
**/
function select_departments($array, $select = 0, $parent = 0, $space = '', $identify_category = false)
{
$arr = $this->department_array($array, $parent);
$return = null;
foreach ($arr as $val)
{
if ($identify_category && !$val['dept_parent']) {
$dot = '.';
} else {
$dot = null;
}
if (($val['dept_id'] != $select) && ($select != -1)) {
$selected = null;
} else {
$selected = ' selected=\'selected\'';
}
$return .= '<option value="' . $dot . $val['dept_id'] . '"' . $selected . '>' . $space . $val['dept_name'] . "</option>\n" .
$this->select_forums($array, $select, $val['dept_id'], $space . ' ');
}
return $return;
}
I've been working on this for nearly two days now, and have rewritten them several times. I am using this as such because I am working with a permission cube and will later incorporate it. This may seem pointless to some to have such functions just to show a department list, but it is very healthy in my opinion for sub categories, and global departments, etc for our nightly reports in our CMS.
Here is how I'm calling it: nqfetch is my custom array function. The only thing I need help with is why this is showing up blank, everything works fine, but the departments in the database are just 'not' showing. {}'s should not be worried about these work, I am simply using them to keep the code from breaking the page. I am calling it like so:
<form action='to come later' method='post'>
{$this->table}
<tr>
<td class='header' colspan='2'>Report</td>
</tr>
<tr>
<td class='tablelight' width='30%'><b>Department?</b></td>
<td class='tabledark'>
<select name='parent'>
<option value='0'>Select One</option>
<option value='0'>----------------------------</option>" .
$this->select_departments($this->department_grab(), $d['dept_parent']) . "
</select>
</td>
</tr>
{$this->etable}
</form>