Optgroup array help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
platinumenyce
Forum Newbie
Posts: 1
Joined: Wed Oct 19, 2011 9:14 am

Optgroup array help

Post by platinumenyce »

Hello,

I'm trying to create an select box utilizing the optgroup tag. The select box should list all the parent jobs as the label and the child jobs as the options.
I have the parent jobs listing, but the problem is getting the child jobs to group with the correct parent job.

Parent Jobs
$parent_job_list = get_parent_job_list();

Child Jobs
$child_job_list = get_child_job_list($job_id);

Code: Select all

//Parent Job List
function get_parent_job_list(){
	//Get parent job list
	$sql = "select
				job_id, name
			from job
			where (par_job_id is null and ((name like '%PJ%') or (name like '%PD%'))) or (par_job_id is null)
			order by job_id";
	$rs = get_rs_array("Penta", $sql);
	return $rs;
}

//Child Job List
function get_child_job_list($job_id){
	//Get child job list
	$sql = "select
				job_id, name
			from job
			where ((par_job_id = ".$job_id.") or (job_id = ".$job_id."))
			order by job_id";
	$rs = get_rs_array("Penta", $sql);
	return $rs;
}

Code: Select all

<tr>
 <td style="text-align: right">Job:</td>
 <td>
	<select name="par" multiple="multiple" size="10">
		<option value="0" selected>ALL</option>
			{section name=par loop=$par_job_list}
				<optgroup label="{$par_job_list[par][0]}, {$par_job_list[par][1]}">
					{section name=job loop=$child_job_list}
						<option value="{$child_job_list[job][0]}">{$child_job_list[job][0]}, {$child_job_list[job][1]}</option>
					{/section}
				</optgroup>
			{/section}
	</select>
 </td>
</tr>
Post Reply