Can anybody help me to make a picture link counter. I have a field in databse call wall_views which is set to 0 at the beginning but should increment after the pic is clicked.
Thanks in advance
Can anybody help me to make a picture link counter. I have a field in databse call wall_views which is set to 0 at the beginning but should increment after the pic is clicked.
Thanks in advance
Here's the idea:
$id=(int)$_GET['id'];
mysql_query("UPDATE walls SET wall_views=wall_views+1 WHERE id=$id");
Thanks a lot
Sorry php_daemon, i think it was over but i have a lil problem again.
$sql="select * from happy_wall_f limit $x,3";
$con=new Connection();
$con->setQuery($sql);
$con->setDatabase(DB_NAME);
$sth1=$con->runQuery();
$pic_count = 0;
echo "<table border=\"1\" align=\"center\">";
echo "<tr>";
echo "<td><p style=\"margin-top:0; margin-bottom:0\"><a target =\"_blank\" href=\"$row[1]\"><img src=\"$row[1]\" align=\"baseline\" width=150 height=113></a></p><p class=\"style1\" align=\"center\" style=\"margin-top:0; margin-bottom:0\">$row[2]</p> <p class=\"style1\" align=\"center\" style=\"margin-top:0; margin-bottom:0\">($row[3])</p><p class=\"style1\" align=\"center\" style=\"margin-top:0; margin-bottom:0\">Views: $row[4]</p></td>";
$pic_count++;
if($pic_count == 3){
echo "</tr>";
echo "<tr>";
$pic_count = 0;
}
}
If i put the id on the url and click the image then all the images on the page will increment the views on the database.
So what should I do so that only the clciked image have increase views in the database.
Can you show the part where you increase the views?
$sql="select * from happy_wall_f limit $x,3";
$con=new Connection();
$con->setQuery($sql);
$con->setDatabase(DB_NAME);
$sth1=$con->runQuery();
$pic_count = 0;
$link_id =1;
echo "<table border=\"1\" align=\"center\">";
echo "<tr>";
echo "<td><p style=\"margin-top:0; margin-bottom:0\"><a target =\"_blank\" href=\"$row[1]\" id = \"$link_id\"><img src=\"$row[1]\" align=\"baseline\" width=150 height=113></a></p><p class=\"style1\" align=\"center\" style=\"margin-top:0; margin-bottom:0\">$row[2]</p> <p class=\"style1\" align=\"center\" style=\"margin-top:0; margin-bottom:0\">($row[3])</p><p class=\"style1\" align=\"center\" style=\"margin-top:0; margin-bottom:0\">Views: $row[4]</p></td>";
$pic_count++;
if($link_id){
$sql1="UPDATE wall_f SET wall_views = wall_views + 1 Where wall_id = $link_id";
$con=new Connection();
$con->setQuery($sql1);
$con->setDatabase(DB_NAME);
$sth2=$con->runQuery();
}
$link_id++;
if($pic_count == 3){
echo "</tr>";
echo "<tr>";
$pic_count = 0;
}
}
if this is done all the pics will increase their views. Also do you think this is an efficient coding? I am not sure ?
here the $link_id is being used to identify the links..
Thanks in advance
Why do you have it in the loop along with the display of the images? You increase the $link_id on every iteration, that makes no sense at all. $link_id is supposed to be taken from the url and the query executed once:
$link_id=(int)$_GET['id'];
if($link_id){
$sql1="UPDATE wall_f SET wall_views = wall_views + 1 Where wall_id = $link_id";
$con=new Connection();
$con->setQuery($sql1);
$con->setDatabase(DB_NAME);
$sth2=$con->runQuery();
}
Thanks again
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.