在我的数据库中,我有一个名为'状态'键的实体,它们有一个非数值(如a, B, Q)
我想使用PHP脚本根据
的值回显不同的内容现在我的页面只是选择键的值。
编辑:对不起人。我试过了:
while( $notify = mysql_fetch_array($resultSet) ) {
echo '</td><td>'.$notify['status'].'</td></tr>';
}
你可以这样做:
while( $notify = mysql_fetch_array($resultSet) ) {
var $output = '</td><td>';
switch( $notify['status'] )
{
case "A":
$output += 'The status is A';
break;
case "B":
$output += 'The status is B';
break;
case "Q":
$output += 'The status is Q';
break;
default:
$output += 'The status is ' .$notify['status'];
break;
}
$output += '</td></tr>';
echo $output;
}
当然,不同情况下的输出不同…
作为@Andre的解决方案的替代方案,您还可以直接在SQL中执行转换:
SELECT CASE status WHEN 'A' THEN 'Approved'
WHEN 'B' THEN 'Basic'
WHEN 'Q' THEN 'Questionable'
ELSE 'Other'
END AS status_word
FROM mytable;