Page 1 of 1

Little Help Please

Posted: Wed Aug 18, 2010 3:50 am
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.

Re: Little Help Please

Posted: Wed Aug 18, 2010 8:08 am
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'");