I have been banging my head on this odd problem for a while not, and figured it time for some more eyeballs on code…
I have two arrays. One that lists all products and one that associates those products with a Session.
I am trying to provide a list of all products with a checkmark to allow the user to associate that product with the session the page is dealing with. ( the sessionid is fixed ). Existing assocations should be displayed already checked…
the problem I am getting is that if any of them are associated, they all get a checkmark…
probably some dumb*** php mistake, but I sure don’t see it…
Thanks
-John
<?= Html::beginForm( '/admin/sessionproducts/save', 'post' ); ?>
<div class="checkboxgroup">
<?php
// loop through all products
foreach( $products as $product )
{
$sessionid = $session['sessionId'];
$productid = $product['productId'];
$id = 'Product' . $productid;
$label = $product['name'];
// set checkmark to 0, in case of no associations
$checkmark=0;
// loop through all associations ( if any ), and set selected if exists..
foreach( $sessionproducts as $sessionproduct )
{
if( $sessionproduct['sessionId'] = $sessionid )
$checkmark = 1;
else
$checkmark = 0;
}
?>
<div>
<?= Html::checkbox( $id, $checked = $checkmark,
$options = ['label' => $label, 'uncheck' => '0'] ); ?>
</div>
<?php
}
?>
</div>
<?= Html::submitButton( 'Update', ['class' => 'btn btn-success']) ?>
<?= Html::a( 'Cancel', ['admin/sessionproducts'], ['class' => 'btn btn-default']) ?>
<?= Html::endForm(); ?>