結果に応じて値を変更する必要があります。PHPを使用してMySQLクエリの結果に応じて画像を表示
<td>'.$row['register_status'].'</td>
<td>'
if($row['status']=='Active')
{
echo '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
'</td>
コードの何が問題になっています。この場合は、「ステータス」私の行がある場合は、「アクティブ」私はテーブルでそのようなものを入れたいですか?ログに
if(mysql_num_rows($result) > 0)
{
$number = 1;
while($row = mysql_fetch_assoc($result))
{
$data .= '<tr>
<td>'.$row['register_status'].'</td>
<td>'
if($row['status']=='Active')
{
echo '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
'</td>
</tr>';
$number++;
}
}
else
{
// records now found
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
、エラーは次のとおりです。
PHP解析エラー:構文エラー、ライン32上の/var/www/html/form/ajax/readRecords.phpで予期しないT_IF、リファラます。http:/localhostform/
ライン32である。
if($row['status']=='Active')
- UPDATE *
は最後に、私のようにコードを更新:
while($row = mysql_fetch_assoc($result))
{
$data .= '<tr>
<td>'.$row['register_status'].'</td>
<td>';
if($row['register_status']=='Active') {
$data .= '<span class="glyphicon glyphicon-true" aria-hidden="true" style="color:green"></span>';
}
else if($row['register_status']=='Inactive')
{
$data .= '<span class="glyphicon glyphicon-time-remove" aria-hidden="true" style="color:red"></span>';
}
else
{
$data .= '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
$data .= '</td>
<td>'.$row['first_name'].'</td>
</tr>';
}
}
else
{
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
しかし、常に他の最後を実行し、唯一
$data .= '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
に結果を印刷するのはなぜ異なるケースに応じて別のアイコンを入れていませんか?