- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
I am working on a project which includes image gallery.Now I want to store number of clicks/counts value into my database(developed in MySQL). I tried to do it in my own way, but problem is count/clicks value for all the images are stored in the database as same value.
The code given below is in the file main.php which displays images that is retrieved from database.The picture.php is the one that retrieves images from database. I have appended the code to count the number of clicks in picture.php so that it counts whenever the image is clicked.
main.php
$query="SELECT * FROM files";
$result=mysql_query($query) or die(mysql_error());
while($fetch=mysql_fetch_array($result)){
echo "<div class=single>
<div class=wrap>
<a href=picture.php?fid=".$offer_id.">
<img src=picture.php?fid=".$offer_id."\">
</a>
</div>
</div>";
}
picture.php
if(isset($_GET['fid']))
{
include "connect.php";
$fid=$_GET['fid'];
$query="SELECT * FROM offers_em WHERE o_id =$fid";
$result=mysql_query($query) or die(mysql_error());
$sql="UPDATE offers_em SET count+=1 WHERE o_id=".$fid;
$sql2=mysql_query($sql);
$name=mysql_result($result,0,"pic_name");
$size=mysql_result($result,0,"size");
$type=mysql_result($result,0,"type");
$content=mysql_result($result,0,"content");
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
}
else{
die("No file ID given...");
}
最佳答案
我不确定MySQL是否支持“+=”,试试SET 计数 = 计数 + 1
编辑:无论如何,一定要考虑对注入(inject)漏洞进行分类,如您帖子下方的评论中所述。
关于php - 使用php在数据库中存储点击次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13358601/
我会写一个例子,这样你就可以理解我了: 例如,我有这 3 个点:(0, 1, 244) - (0, 1, 255) - (1, 2, 133) 实际上,当 2 个点具有相同的 (x, y) 时,我需要
我是一名优秀的程序员,十分优秀!