Note that there are some explanatory texts on larger screens.

plurals
  1. POStore number of clicks in database using php
    primarykey
    data
    text
    <blockquote> <p>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.</p> <p>The code given below is in the file <strong>main.php</strong> which displays images that is retrieved from database.The <strong>picture.php</strong> is the one that retrieves images from database. I have appended the code to count the number of clicks in <strong>picture.php</strong> so that it counts whenever the image is clicked.</p> </blockquote> <p><strong>main.php</strong></p> <pre><code> $query="SELECT * FROM files"; $result=mysql_query($query) or die(mysql_error()); while($fetch=mysql_fetch_array($result)){ echo "&lt;div class=single&gt; &lt;div class=wrap&gt; &lt;a href=picture.php?fid=".$offer_id."&gt; &lt;img src=picture.php?fid=".$offer_id."\"&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt;"; } </code></pre> <p><strong>picture.php</strong></p> <pre><code> 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..."); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload