Home › Forums › Front-end Issues › Value comparison is true for all values
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
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
The topic ‘Value comparison is true for all values’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.