duandaodao6951 2019-01-04 05:14
浏览 74
已采纳

显示图像而不是变量的值[重复]

This question already has an answer here:

I'm just getting to know PHP so please bear with me if my question is not clear. I have a user registration page that collects a field called "zodiac" which is uploaded to the database. I can easily call the variable $zodiac and the value, let's say, "Aries" is displayed on the desired user's page depending on who is logged in. However, instead of the text, I'd like to display a corresponding image file on the page from my local drive. I've tried the "elseif" statements but it doesn't seem to be working. Although I do get an image with the statement it doesn't seem to change when I change users:

These are properly being loaded to the desired page:

$this->table->add_row("<b>".$username."</b>&ensp;&ensp;Age:".$age."&ensp;&ensp;".$zodiac);

if($zodiac='Aries') {
   echo '<img src="../assets/images/zodiac/Aries.png" width="45" height="35" />';
    }elseif($zodiac='Taurus') {
   echo '<img src="../assets/images/zodiac/Taurus.png" width="45" height="35" />';
    }elseif($zodiac='Gemini') {
   echo '<img src="../assets/images/zodiac/Gemini.png" width="45" height="35" />';

The "elseif" statement continues to the end.

Hope this makes sense. Thanks for any input.

</div>
  • 写回答

1条回答 默认 最新

  • duanshan1977 2019-01-04 05:25
    关注

    You are mixing the assignment operator = with the equality operator ==.

    // assign 1 to variable a
    $a = 1
    
    // compare variable a with 1
    $a == 1
    

    So to fix your code:

    if ($zodiac == 'Aries')
    {
    ...
    }
    

    You'll find more info about the operators and how they work here: https://secure.php.net/manual/en/language.operators.assignment.php https://secure.php.net/manual/en/language.operators.comparison.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中