donglianglu8136 2014-08-07 04:55
浏览 15
已采纳

多个if代码不能一起工作? (PHP)

I have a series of if codes that need to be put together but the code acts weird and chooses the last if code.

if($boardid='1'){ $altboard='13' and $title='Archives' ;}
elseif($boardid='2'){ $altboard='14' and $title='Archives' ;}

so this code turns out to work, but it cant be repeated to finish the rest of the codes

the code that doesn't work is:

if($boardid=='1'){ $altboard='13' and $title='Archives' ;}
if($boardid='2'){ $altboard='14' and $title='Archives' ;}
if($boardid='3'){ $altboard='15' and $title='Archives' ;}
if($boardid='6'){ $altboard='16' and $title='Archives' ;}
if($boardid='7'){ $altboard='17' and $title='Archives' ;}

and there is more if codes to add, but i didn't add them, as it only uses whatever turns out to be the last of the lines regardless of boards, even though it clearly recognizes the boards. so what gives and how do i make a series of if codes work together? I have another file with the exact same thing and it reacts the same. If then elseif for the rest of the code doesn't work and neither does alternating if and else if.

putting two equal signs Works fine with The above mentioned code but not with the second mentioned code which is this

    if($wrong=='0'){$prize='1000';}
    if($wrong=='1'){$prize='700';}
    if($wrong=='2'){$prize='500';}
    if($wrong=='4'){$prize='200';}
    if($wrong=='5'){$prize='100';}

Unlike the last one where it keeps only the last code this one takes only the first one. so the prize always turns out to be 1000. any help here

  • 写回答

3条回答 默认 最新

  • dtp19819 2014-08-07 04:58
    关注

    should be like

    if($boardid=='1'){ $altboard='13'; $title='Archives';}
    if($boardid=='2'){ $altboard='14'; $title='Archives';}
    if($boardid=='3'){ $altboard='15'; $title='Archives';}
    if($boardid=='6'){ $altboard='16'; $title='Archives';}
    if($boardid=='7'){ $altboard='17'; $title='Archives';}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?