dongzhuonao8429 2017-05-17 17:13
浏览 31
已采纳

laravel 5错误:语法错误意外'如果'在连接中间[重复]

This question already has an answer here:

I have this error : error : syntax error, unexpected 'if' (T_IF) when I run this code :

$output="";
        $search_iy=DB::table('iy_tkt')->where('name','LIKE','%'.$request->search.'%')
                                      ->orWhere('tkt_no','LIKE','%'.$request->search.'%')->get();
        if ($search_iy)
        {
            foreach ($search_iy as $search_iy2 ){
                        $output.='<tr>'.

                                '<td>'. strtoupper("$search_iy2->air_code").'</td>'.
                                '<td>'. strtoupper("$search_iy2->name") .'</td>'.
                                '<td>'. $search_iy2->tkt_no .

                                   if ($search_iy2->tkt_file)  
                                        '<a target="_blank" href="tkt_file/'.$search_iy2->tkt_file.'"> &nbsp; TKT </a>'.
                                         '</td>'.

                            '</tr>';  


                        }
                            return Response($output);

        }
    }

I tried to change this line to many thing :

'<td>'. $search_iy2->tkt_no .
'<td>'. $search_iy2->tkt_no ;
'<td>'. $search_iy2->tkt_no .''.

Same Error

</div>
  • 写回答

1条回答 默认 最新

  • douduo2407 2017-05-17 17:17
    关注

    You cannot have your if inside of setting the variable.

    $output.='<tr>'.
    '<td>'. strtoupper("$search_iy2->air_code").'</td>'.
    '<td>'. strtoupper("$search_iy2->name") .'</td>'.
    '<td>'. $search_iy2->tkt_no;
    
    if ($search_iy2->tkt_file)  
        $output .= '<a target="_blank" href="tkt_file/'.$search_iy2->tkt_file.'"> &nbsp; TKT </a>';
    
    $output .= '</td>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?