我的代码从数据库中选择,写出信息然后运行一个 else if 循环来决定输出什么代码:
<?php
echo '<p>the loop<p><br>
<p>Accreditations</p>';
if ($fields['accreditations1']==1){echo 'HTML CODE 1';} else {
if ($fields['accreditations1']==2){echo 'HTML CODE 2';} else {
if ($fields['accreditations1']==3){echo 'HTML CODE 3';} else {
if ($fields['accreditations1']==4){echo 'HTML CODE 4';} else {
if ($fields['accreditations1']==5){echo 'HTML CODE 5';} else {
if ($fields['accreditations1']==6){echo 'HTML CODE 6';} else {
if ($fields['accreditations1']==7){echo 'HTML CODE 7';} else {
if ($fields['accreditations1']==0){echo '';}
if ($fields['accreditations2']==1){echo 'HTML CODE 1';} else {
if ($fields['accreditations2']==2){echo 'HTML CODE 2';} else {
if ($fields['accreditations2']==3){echo 'HTML CODE 3';} else {
if ($fields['accreditations2']==4){echo 'HTML CODE 4';} else {
if ($fields['accreditations2']==5){echo 'HTML CODE 5';} else {
if ($fields['accreditations2']==6){echo 'HTML CODE 6';} else {
if ($fields['accreditations2']==7){echo 'HTML CODE 7';} else {
if ($fields['accreditations2']==0){echo '';}
if ($fields['accreditations3']==1){echo 'HTML CODE 1';} else {
if ($fields['accreditations3']==2){echo 'HTML CODE 2';} else {
if ($fields['accreditations3']==3){echo 'HTML CODE 3';} else {
if ($fields['accreditations3']==4){echo 'HTML CODE 4';} else {
if ($fields['accreditations3']==5){echo 'HTML CODE 5';} else {
if ($fields['accreditations3']==6){echo 'HTML CODE 6';} else {
if ($fields['accreditations3']==7){echo 'HTML CODE 7';} else {
if ($fields['accreditations3']==0){echo '';}
echo '<br />';
if ($fields['accreditations4']==1){echo 'HTML CODE 1';} else {
if ($fields['accreditations4']==2){echo 'HTML CODE 2';} else {
if ($fields['accreditations4']==3){echo 'HTML CODE 3';} else {
if ($fields['accreditations4']==4){echo 'HTML CODE 4';} else {
if ($fields['accreditations4']==5){echo 'HTML CODE 5';} else {
if ($fields['accreditations4']==6){echo 'HTML CODE 6';} else {
if ($fields['accreditations4']==7){echo 'HTML CODE 7';} else {
if ($fields['accreditations4']==0){echo '';}
if ($fields['accreditations5']==1){echo 'HTML CODE 1';} else {
if ($fields['accreditations5']==2){echo 'HTML CODE 2';} else {
if ($fields['accreditations5']==3){echo 'HTML CODE 3';} else {
if ($fields['accreditations5']==4){echo 'HTML CODE 4';} else {
if ($fields['accreditations5']==5){echo 'HTML CODE 5';} else {
if ($fields['accreditations5']==6){echo 'HTML CODE 6';} else {
if ($fields['accreditations5']==7){echo 'HTML CODE 7';} else {
if ($fields['accreditations5']==0){echo '';}
if ($fields['accreditations6']==1){echo 'HTML CODE 1';} else {
if ($fields['accreditations6']==2){echo 'HTML CODE 2';} else {
if ($fields['accreditations6']==3){echo 'HTML CODE 3';} else {
if ($fields['accreditations6']==4){echo 'HTML CODE 4';} else {
if ($fields['accreditations6']==5){echo 'HTML CODE 5';} else {
if ($fields['accreditations6']==6){echo 'HTML CODE 6';} else {
if ($fields['accreditations6']==7){echo 'HTML CODE 7';} else {
if ($fields['accreditations6']==0){echo '';}
?>
首先我需要做些什么来关闭ifs吗?还有更短的方法吗?