Hi,
I’m trying to fit answers of a form into an html table.
But when I verify values, it seems to be true for every answer even if there’s only one (which is the behavior cause I’m using radio buttons).
With the following code, I get a cross into each cell and not only the one which is concerned :
<?php
$fields = acf_get_fields('71'); //my field group
$values = get_fields();
if( $fields ) {
echo '<table>';
foreach ($fields as $field) {
echo '<tr>';
echo '<td class="detail-key">' . $field['label'] . '</td>';
if ( $value = 'N/E' ) {
echo '<td class="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
if ( $value = 'N/A' ) {
echo '<td class="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
if ( $value = 'C' ) {
echo '<td class="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
if ( $value = 'N/C' ) {
echo '<td class="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
Thanks for any help
you need to use ==
in comparisons.
Well I tried this and it gives exactly the opposite behavior : no answer at all, all the cells are empty as if there was no value.
I also do not see where you’re getting $value
from. I’m assuming that you need to get it from $values
<?php
$fields == acf_get_fields('71'); //my field group
$values == get_fields();
if( $fields ) {
echo '<table>';
foreach ($fields as $field) {
$value = $values[$field['name']];
echo '<tr>';
echo '<td class=="detail-key">' . $field['label'] . '</td>';
if ( $value == 'N/E' ) {
echo '<td class=="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
if ( $value == 'N/A' ) {
echo '<td class=="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
if ( $value == 'C' ) {
echo '<td class=="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
if ( $value == 'N/C' ) {
echo '<td class=="detail-value">⨯</td>';
} else {
echo '<td></td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
Yes ! That’s it…
I forgot to get the value $value = $values[$field['name']];
Thanks a lot