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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100