duanqie8549 2019-08-09 13:44
浏览 40
已采纳

如何使用PHP函数连接HTML <img>?

Been having trouble displaying an avatar for my website. I store all of them in a custom folder called images, where either I or the users create them. The avatar shows only if youre the exact id the avatar is named after. Example:

I have a user who's id is 1, I also have an image with a name 1.png, so this PHP code block gets the link where the images are stored at, fetches the users id and then searches the page for that image that is name after the id.

Here's the code block I've been having issues with:

<img id='avatar' 
     class='Avatar'
     src='https:/mysitelink.com/images/' + <?php echo"" . $fetchuser->id . ""; ?>.png?r=<?php echo "$RefreshRate"; ?>' 
     height='350'
     width='350'
     onerror="this.src='mysitelink.com/images/default.png'" />

The mysitelink.com is inserted by me to hide the link of the website.

  • 写回答

2条回答 默认 最新

  • dqq22391 2019-08-09 14:27
    关注

    Try like below :

    <img id='avatar' 
         class='Avatar'
         src='https://mysitelink.com/images/<?php echo $fetchuser->id.'.png'; ?>?r=<?php echo "$RefreshRate"; ?>' 
         height='350'
         width='350'
         onerror="this.src='mysitelink.com/images/default.png'" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?