0

Syntax error unexpected if

$data = array();
$data['measure'] = '';
    $measure=$db->execute("select measure from measures where delet='0'");
    while($msrevalues=$measure->fetch_assoc())
    {
        $data['measure'] .= '<option value="'.$msrevalues['measure'].'"'. if($tqmsre['measure']==$msrevalues['measure']){ echo "selected";}. '>'.$msrevalues['measure'].'</option>';
    }
echo json_encode($data);exit();

What is the error in this if statement..?
Help me please...

Sambhu M R
  • 297
  • 5
  • 23

1 Answers1

0

Do the If statement separately instead inside the $data

<?php
$data = array();
$data['measure'] = '';
    $measure=$db->execute("select measure from measures where delet='0'");
    while($msrevalues=$measure->fetch_assoc())
    {
        $selected = ($tqmsre['measure']==$msrevalues['measure']) ? 'selected="selected"' : '';
        $data['measure'] .= '<option value="'.$msrevalues['measure'].'" '. $selected. '>'.$msrevalues['measure'].'</option>';
    }
echo json_encode($data);
exit();
?>
J.K
  • 1,382
  • 1
  • 11
  • 27
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – Rizier123 Apr 22 '16 at 05:41