2015-09-07 77 views
-3

我有语法错误,我下面的代码语法错误,在PHP代码

<?php 
If (!empty($_SESSION['LogedinStudentId'])) { 
echo '<h3>Your Scholarship Applications:</h3> 
<table width="100%" class="table table-bordered"> 
<tr> 
<th scope="col">Sr.No.</th> 
<th scope="col">Date of Application</th> 
<th scope="col">Course Type</th> 
<th scope="col">Course Description</th> 
<th scope="col">Subject</th> 
<th scope="col">Applied for Semester No.</th> 
<th scope="col">Scholarship Status</th> 
<th scope="col">View/Print</th> 
</tr> 
<tr> 
<td>' . ++$serialno . '</td> 
<td>' . if(empty($row_studentdashboard['DateofApplication'])) { 
echo '&nbsp;'; 
} else { 
echo date("d-m-Y", strtotime($row_studentdashboard['DateofApplication'])); 
}; 
. '</td> 
<td>' . $row_studentdashboard['CourseType'] .'</td> 
<td>' . $row_studentdashboard['CourseDescriptionLong'] .'</td> 
<td>' . $row_studentdashboard['Subject'] .'</td> 
<td>' . $row_studentdashboard['ApplyForSemYear'] .'</td> 
<td>' . $row_studentdashboard['ScholarshipStatus'] .'</td> 
<td><a href="#">View</a>/<a href="#">Print</a></td> 
</tr> 
</table>'; 
} else { 
echo '<h3>You do not have any application pending</h4>'; 
} 
?> 

我收到语法错误就行无法逃避的HTML。 17和22.第二个(嵌套的)if语句抛出语法错误。我无法判断出了什么问题。如果我运行这第二个if语句之外的HTML它工作正常。 任何人都可以指出什么是错的?

+1

什么语法错误? – peter

+0

'if(condition){echo and concatenate properly}' –

+0

@激光*“什么语法错误?” - 可能是“意想不到的T_IF - T_ECHO”或沿着那条线;-) –

回答

2

你在做什么是回声语句内的if语句。这是错误的。 在html之外运行if语句并创建一个变量,稍后在html中打印该变量。 A类此:

if(empty($row_studentdashboard['DateofApplication'])) { 
$text = '&nbsp;'; 
} else { 
$text = date("d-m-Y", strtotime($row_studentdashboard['DateofApplication'])); 
} 

.....

<td>' . ++$serialno . '</td> 
<td>' . $text . '</td> 
2

您不应该将if语句连接到字符串。这是你做了什么线17/18

+0

你能详细解释一下吗? –

+1

说:​​'这是一种罪过。如果(空($ row_studentdashboard ['DateofApplication'])){ – peter

2

尝试:

<?php 
    if (isset($_SESSION['LogedinStudentId']) && !empty($_SESSION['LogedinStudentId'])) { 
     $out = '<h3>Your Scholarship Applications:</h3>'; 
     $out .= '<table width="100%" class="table table-bordered">'; 
     $out .= '<tr>'; 
     $out .= '<th scope="col">Sr.No.</th>'; 
     $out .= '<th scope="col">Date of Application</th>'; 
     $out .= '<th scope="col">Course Type</th>'; 
     $out .= '<th scope="col">Course Description</th>'; 
     $out .= '<th scope="col">Subject</th>'; 
     $out .= '<th scope="col">Applied for Semester No.</th>'; 
     $out .= '<th scope="col">Scholarship Status</th>'; 
     $out .= '<th scope="col">View/Print</th>'; 
     $out .= '</tr>'; 
     $out .= '<tr>'; 
     $out .= '<td>' . ++$serialno . '</td>'; 
     $out .= '<td>'; 
     if(!isset($row_studentdashboard['DateofApplication']) || empty($row_studentdashboard['DateofApplication'])) { 
      $out .= '&nbsp;'; 
     } else { 
      $out .= date("d-m-Y", strtotime($row_studentdashboard['DateofApplication'])); 
     }; 
     $out .= '</td>'; 
     $out .= '<td>' . $row_studentdashboard['CourseType'] .'</td>'; 
     $out .= '<td>' . $row_studentdashboard['CourseDescriptionLong'] .'</td>'; 
     $out .= '<td>' . $row_studentdashboard['Subject'] .'</td>'; 
     $out .= '<td>' . $row_studentdashboard['ApplyForSemYear'] .'</td>'; 
     $out .= '<td>' . $row_studentdashboard['ScholarshipStatus'] .'</td>'; 
     $out .= '<td><a href="#">View</a>/<a href="#">Print</a></td>'; 
     $out .= '</tr>'; 
     $out .= '</table>'; 
    } else { 
     $out = '<h3>You do not have any application pending</h4>'; 
    } 
    echo $out; 
+0

你写过这个很麻烦。但是你的开头是*“Try”*,对于OP在哪里犯错误并没有太多的说法。 *启迪我们* ;-) –

+0

大声笑我想展示另一种方式来写他的代码,更容易阅读,(我认为^^) – Fky

+0

好,现在我们需要看看OP是否会打你的;-) –