douzhang3356 2016-10-10 19:03
浏览 31
已采纳

PHP / JS / SQL - 单击图像时提醒查询结果并不总是有效

Inside a php file i construct a table that i then echo and it shows the results of a query. One of the columns contains cells where i have an image. What i want to do is 1)when i hover over the image to see the string stored in the variable and 2)when i click on the image to see the same string in an alert box.

My code for that is the following

echo "<td href='#' onClick=alert('".$ResultTable[$i][10]."'); style='text-align: center;'><img src='IconImage.png' width='50' height='50' title='".$ResultTable[$i][10]."'/></td>";

My problem is that the alert box does not always work.

Some more info: The

$ResultTable[$i][10]

Contains a string of size

Notes varchar(255) DEFAULT '---',

If the user did not specify that input, i actually insert a small 4 letter word in greek instead of letting the sql insert the default.

My problem is that if i give as input small words in greek or let the php insert the 4 letter greek word, the alert box works as intended. If i give bigger inputs in greek, it does not work at all. When it comes to english, it does not work at all, no matter the length of the input.

Note that each time i insert or search in the database i use

   mysqli_query($con,"SET NAMES 'utf8'");
   mysqli_query($con,"SET CHARACTER SET 'utf8'");

This is my first post here, so please bear with me if the question's format is messed up or i provided insufficient info. I will provide any info requested. Thank you very much!

  • 写回答

1条回答 默认 最新

  • dp7311 2016-10-10 19:14
    关注
    onclick=\"alert('.....'\"
    

    You need to wrap your onclick element inside a string, since you are manually outputting this you'll need to use the backslash to cancel it.

    Or you can do this much more readable example:

    <tr onclick="alert('?<=$varHere;?>')">
    

    Using the shorthand PHP will basically output the result of whats between the delimiters meaning you do not need to add echo

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

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了