Little Help Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shadowc
Forum Newbie
Posts: 2
Joined: Tue Aug 17, 2010 3:35 pm

Little Help Please

Post by shadowc »

Am trying to make a click counter in php and mysql, but all i can do, i make hit counter it only counts every hit on the web where links are shown. Here's what i've done so far:

if you choose to help me here are the fields in the database:
Name,Link,id,hits,number

Code: Select all

mysql_select_db("DATABASE", $con);

$result = mysql_query("SELECT * FROM links ORDER BY hits DESC LIMIT 15");

while($row = mysql_fetch_array($result))
{
echo "<a href=$row[Link]>$row[Name]</a>";
echo "<br/>";
}

mysql_query("UPDATE links SET hits=hits+1");

I try to make it like this but it wont count at all:

Code: Select all

while($hits= mysql_fetch_array($result))
{
$link=$hits[Link];
mysql_query("UPDATE links SET hits=hits+1 WHERE Link =$link");
}
Before i reached here everything went well, but here i totally blocked , so if anyone could help me would be the best thing, Thanks.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Little Help Please

Post by cpetercarter »

I think that you need to surround $link with quotation marks, so that mysql knows that it is dealing with a string:

Code: Select all

mysql_query("UPDATE links SET hits=hits+1 WHERE Link = '$link'");
Post Reply