Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem displaying a grid

Status
Not open for further replies.

webslinga

Programmer
Jun 20, 2006
55
US
Hey all,
Have a logical problem on my hands here. Please let me know if you have any ideas.
I want to map a list of "zones" and "activity groups" and display a checked checkbox if already assigned in the database and an unchecked box if not assigned. The only problem is that it is displaying another set of checkboxes after the first set. Below is the code. if you find funny looking function such as form_tag and checkbox_tag, just know that I am working through a framework. Thanks all. Any help is greatly appreciated.

Code:
<?php
// get count for the activity group in order to get the colspan for header
$numActGroup = count($allActGroup);

?>
<?php echo form_tag('property'); ?>
<div id='vrs_actionbar'>
<?php echo submit_tag('Submit'); ?>
</div>
<div class='vrs_grid' style='width:800px'>
<table border=0 class='vrs_datagrid'>
<tr><th></th><th colspan=<?php echo $numActGroup?>><center>Zone Mappings</center></th></tr>
<tr><th></th>
<?php foreach($allActGroup as $actGroup) 
{?>
<th><?php echo $actGroup->getDescription() . '{' . $actGroup->getActgroupUnid() . '}'; ?></th>

<?php } ?>
</tr>
<?php
foreach($mapZones as $mapZone){
	$mZoneID[] = $mapZone->getZoneUnid();
	$mActGroupID[] = $mapZone->getActgroupUnid();
}

// dump the contents of both of the array
vrsTools::VRSPrintr($mZoneID, 'mZoneID');
vrsTools::VRSPrintr($mActGroupID, 'mActGroupID');
?>
<?php echo 'mZoneID: ' . count($mZoneID) . '<BR>'; ?>
<?php echo 'allActGroup: ' . count($allActGroup) . '<BR>'; ?>
<?php foreach($allZones as $zone) 
{?>
<tr <?php echo altrow(); ?>><th><?php echo 'Zone ' . $zone->getName() . '{' . $zone->getZoneUnid() . '}'; ?></th>
<?php foreach($allActGroup as $actGroup){ ?>
<?php // ASSUMPTION: The number of elements in $mzoneID and $mActGroupID are the same ?>
<?php
for($i = 0; $i < count($mZoneID); $i++) {
	if(($zone->getZoneUnid() == $mZoneID[$i]) && ($actGroup->getActgroupUnid() == $mActGroupID[$i]))
	{	?>
	<td>
		<?php echo 'getZoneUnid:' . $zone->getZoneUnid() . checkbox_tag('check[]', '1', true) . 'getActgroupUnid:' . $actGroup->getActgroupUnid();?>
		</td>
	<?php }
	else
	{ ?>
	<td>
	<?php	echo checkbox_tag('check[]', '1', false); ?>
		</td>
	<?php
	}
//	echo 'i: '. $i . '<BR>';
} 
// break;
?>
<?php } ?>

</tr>
<?php } ?>
</table>
</form>
</div>
 
i'm not sure i have enough understanding of what you're trying to do.

could you post a mocked up example of what you want the output to look like.
 
<?php
// get count for the activity group in order to get the colspan for header
$numActGroup = count($allActGroup);

?>
<?php echo form_tag('property'); ?>
<div id='vrs_actionbar'>
<?php echo submit_tag('Submit'); ?>
</div>
<div class='vrs_grid' style='width:800px'>
<table border=0 class='vrs_datagrid'>
<tr><th></th><th colspan=<?php echo $numActGroup?>><center>Zone Mappings</center></th></tr>
<tr><th></th>
<?php foreach($allActGroup as $actGroup)
{?>
<th><?php echo $actGroup->getDescription() . '{' . $actGroup->getActgroupUnid() . '}'; ?></th>

<?php } ?>
</tr>
<?php
foreach($mapZones as $mapZone){
$mZoneID[] = $mapZone->getZoneUnid();
$mActGroupID[] = $mapZone->getActgroupUnid();
}
?>

<?php foreach($allZones as $zone)
{
?>
<tr <?php echo altrow(); ?>><th><?php echo 'Zone ' . $zone->getName() . '{' . $zone->getZoneUnid() . '}'; ?></th>
<?php foreach($allActGroup as $actGroup){ ?>
<?php // ASSUMPTION: The number of elements in $mzoneID and $mActGroupID are the same ?>
<?php
if((in_array($zone->getZoneUnid(), $mZoneID)) && (in_array($actGroup->getActgroupUnid(), $mActGroupID)))
{ ?>
<td>
<?php
echo 'getZoneUnid:' . $zone->getZoneUnid() . checkbox_tag('check[]', '1', true) . 'getActgroupUnid:' . $actGroup->getActgroupUnid();
?>
</td>
<?php }
else
{ ?>
<td>
<?php echo checkbox_tag('check[]', '1', false); ?>
</td>
<?php
}
?>

<?php } ?>
</tr>
<?php

} ?>

</table>
</form>
</div>

The mockup should look something like this:
Activity A | Activity B | Activity C | Activity D
Zone A |_| |_| |_| |_|
Zone B |_| |_| |_| |_|
Zone C |_| |_| |_| |_|
Zone D |_| |_| |_| |_|


where the zones and the acivities are being pulled from the database. When pulling from the database I also want to display any activities and zones that are already "mapped" to each other by displaying a check in the checkbox. Hope this helps. Please ask if you need any more insight about what I am trying to do. Thanks a lot!
 
ok. you've got a lot of stuff going on here which you're not posting. i.e. the class methods and properties and the structure of your arrays. i'm not sure why you have an array of objects either. are you sure that's efficient for your application?

it is difficult to guess the intersection between the activities and the zones and how the intersection maps to your arrays. typically you would store the id of one as a foreign key equivalent in the other.

this code snip
Code:
 if((in_array($zone->getZoneUnid(), $mZoneID)) && (in_array($actGroup->getActgroupUnid(), $mActGroupID)))
looks a bit strange and may not give you the expected results. don't you actually need to follow this kind of logic:
Code:
$foundKeys_1 = array_keys($mZoneID,$zone->getZoneUnid());
$foundKeys_2 = array_keys($mActGroupID,$actGroup->getActgroupUnid());
if (in_array($foundKeys_1, $foundKeys_2)):
  //the box can be checked
else:
  //the box can be unchecked
endif;

return the key of mZoneID that contains the value of
 
It seems like you got cut off there jpadie. can you elaborate on that last line where you were trying to explain mZoneID? I would appreciate that a lot. Thanks for your help so far. And also is your alternative (the array_keys) seeking to replace that if statement? Thanks.
 
not cut off - just failed to delete the last line. i was going to write the pcode but decided instead just to write the code as i thought it would be more helpful.

the code proposed above would be substituted for the if conditional that you currently have.

the code works by the following logic:

* find all the keys of each array that contain the current value of getzoneID and getActGroupID.
* there can be more than one key in each array that has these values but we need to see whether there is an intersection
* this is achieved by the in_array function
* if there is an intersection then print a checked checkbox
else print an unchecked checkbox
 
jpadie,
I am sorry but that's not the solution that I am looking for. Rememeber, $mZoneID is the array of zone id's and $mActGroupID is the array of activity group ID's. I want the table to display a checked checkbox when the cell is in the [mZoneID, mActGroup] element. Hope that makes sense.
Thank you so much for your help so far jpadie.
 
jpadie,
Thank you for all your help. I figured it out. Thanks for putting my head back on straight for me! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top