Jump to content

Count clicks


djonk

Recommended Posts

Hi everyone,

here's the deal: I have made a link directory (wehoo, another one) and everything is working fine. People can add links and everything is heaven, but! I want users to be able to rate every link, and I find myself rather clueless. I have a table in my database called "dir_pages" where all the links/URLs are, and then I have a table called "ratings", which contains the following fields: id, URLID (goes with id in the table "dir_pages" so the thing is synchronised), rating, ip, timestamp. The database structure works fine, since I can rate (that is, manually insert values to links within mysql), but I have no idea on how to make my users able to do this.  Now, I understand that I have to do something which tells mySQL to set a new rating value to the link in question, but I have no clue on how to do it. This is what I have done so far:

 

<?php
$objConn = mysql_connect ('localhost', 'hellothere', 'blablablablalba');
mysql_select_db('hellothere');
$strQuery = mysql_query("
SELECT dir_pages.url, dir_pages.title, dir_pages.id, dir_pages.description, dir_categories.name 
    FROM dir_pages
    LEFT JOIN dir_categories ON dir_categories.id = dir_pages.category
WHERE dir_pages.accepted = 'y'
    ORDER BY dir_pages.id 
    DESC LIMIT 20 

") or exit (mysql_error());
while ($r = mysql_fetch_array($strQuery))
{
    
    echo " "."» <a href=".$r['url']." target="._blank.">".$r['title']."</a>» ";
    $strQuery2 = mysql_query("SELECT rating from ratings  where URLID=$r[id]") or exit (mysql_error());
    $ratesum = 0;$nr_rates=mysql_numrows($strQuery2);
    while ($r2 = mysql_fetch_array($strQuery2))
    {
    $ratesum=$ratesum+$r2[rating];
    }
    $str ="(";
    if ($ratesum>0) {
$str = $str.$ratesum/$nr_rates."/5 after ";
    } 
    $str=$str.$nr_rates. ($nr_rates==1 ? " vote" : " votes").")";
    echo $str." "."» <a href=".$r2[urlID].">vote!</a>";
    echo "<br>"." "."Category:"." "."<b>"."<i>".$r['name']."</i>"."</b>"."<br>"." ".$r['description']."<br>"."<HR SIZE=1 COLOR=#DDDDDD>";
}


mysql_close($objConn);
?>

 

Any help is very appreciated! :)

Link to comment
https://forums.phpfreaks.com/topic/48175-count-clicks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.