0

Here is code without mysql

foreach ( $transaction_type as $i1=>$opt1 ) : 
echo '<option value="' .htmlspecialchars($opt1) .'"' .( 
(
htmlspecialchars($opt1) == htmlspecialchars($_POST['transaction_type'][$i])
)
? 'selected' : "" ) .'>'.htmlspecialchars($opt1) .'</option>';
endforeach;

Trying to modify. If in mysql certain field exists value, the value from mysql is the selected value. Else, echo the same as in code above.

Update

Here is code that at least for me is much more understandable. All works.

foreach ( $transaction_type as $i1=>$opt1 ) {
?>

<option value="<?php echo htmlspecialchars($opt1);?>"
<?php 
if (
($opt1 == $_POST['transaction_type'][$i]) OR ($opt1 == $result[VatReturnTransactionType01])
}
{
echo 'selected';
}
?> >

<?php echo htmlspecialchars($opt1); ?>

</option>

<?php
}
?>

1 Answer 1

1

Very difficult to read.. there might be an extra bracket or a bracket missing but ...

foreach ( $transaction_type as $i => $opt1 ) : 
    $option = '<option value="' .htmlspecialchars($opt1) .'"';

   if(($result[VatReturnTransactionType01] != '' AND 
       htmlspecialchars($opt1) == htmlspecialchars($result[VatReturnTransactionType01]))
       OR htmlspecialchars($opt1) == htmlspecialchars($_POST['transaction_type'][$i]))
   {
       $option .= 'selected';
   }

   $option .= '>'.htmlspecialchars($opt1) .'</option>';
endforeach;
Sign up to request clarification or add additional context in comments.

7 Comments

Get blank page. Yes, difficult. Possibly will try to make something simpler.
I missed a bracket at the end of the second line of the if statement ;)
Unfortunately can not get it to work. Checked brackets. The first after if matches the last after [$i])) Second after if matches VatReturnTransactionType01]). Removed last brackets from [VatReturnTransactionType01])) and [$i]))
Ok, so the syntax is correct but is the logic correct? Double check that.
Tried, but can not get to work... for my brains not understandable:)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.