-2

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

thecoder
  • 11
  • 5

1 Answers1

0

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>';
Derek
  • 2,927
  • 3
  • 20
  • 33
  • I tried this : ''. $search_iy2->tkt_no; but condition if not working then , – thecoder May 17 '17 at 17:25
  • I mean when I do this : ''. $search_iy2->tkt_no; condition after that not working , code execute with no error , but as I said the condition and other code not show in page. – thecoder May 17 '17 at 17:29
  • try changing the `if` to this `if (isset($search_iy2->tkt_file))` – Derek May 17 '17 at 17:31
  • if (isset($search_iy2->tkt_file)) also this not working , but when delete this line if ($search_iy2->tkt_file) . the rest of code working good – thecoder May 17 '17 at 17:42
  • @thecoder can you `var_dump($search_iy2->tkt_file);`? – Derek May 17 '17 at 17:52
  • Dear Derek ,You are a genius man, I didn't read your solve that your wrote it up, carefully,but now just I add to every line ( $output .= ) after ( if ) as you said , and It is work very good , really thank you . – thecoder May 18 '17 at 03:35
  • @thecoder Hey! I'm glad you were able to get it working! Would you mind marking this as correct so if people have further problems they can see what fixes it :) – Derek May 18 '17 at 03:36
  • Ok , Done! , Thank you . – thecoder May 18 '17 at 03:42