Answer the question
In order to leave comments, you need to log in
How to add php code to 'echo'?
The form is rendered via 'echo' for each item. There is also a field for rating. Here's the suggested code, but how would you add it to 'echo' ? There may be other options for 'checked' radio depending on which rating is from 1 to 5 .
<?php $checked = 5;
$count = 5;
?>
<?php for($i = 1; $i <= $count; $i++): ?>
<?php if($i == $checked):?>
<input class="rating-input" id="mod<?=$i?>'" name="radio-rating" type="radio" value="<?=$i?>" checked>
<label class="rating-star" for="mod<?=$i?>" ></label>
<?php else:?>
<input class="rating-input" id="mod<?=$i?>'" name="radio-rating" type="radio" value="<?=$i?>">
<label class="rating-star" for="mod<?=$i?>" ></label>
<?php endif;?>
<?php endfor;?>
Answer the question
In order to leave comments, you need to log in
What is the problem? In laziness?
<?php
$checked = 5;
$count = 5;
for($i = 1; $i <= $count; $i++) {
$isChecked = $i == $checked ? 'checked' : '';
echo "
<input class='rating-input' id='mod{$i}' name='radio-rating' type='radio' value='{$i}' {$isChecked}>
<label class='rating-star' for='mod{$i}' ></label>
";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question