title: Click counter via Mysql database
body: <pre><code>Table: links
  
  id     link_ref             name          clicks   unique_clicks       url
  1    external_link      EXTERNAL LINK        2         1            .index.php    
  
  
  Table:links_clicks
  
  id   link_id     ip     date    hour
  1       2      an_ip  a_date  a_hour
  </code></pre>
  
  <p>These are the tables and below is the code I have tried:</p>
  
  <pre><code>$querym = mysql_query("SELECT * FROM `links` RIGHT JOIN `links_clicks` ON `links`.`id`=`links_clicks`.`link_id`");
  while ($row = mysql_fetch_assoc($querym))
  {
  Echo $row['link_ref']."&lt;br&gt;";
  }
  </code></pre>
  
  <p>What I want is to display an output with all the links from "links" table and how many clicks have been made on each of them in the last 24 hours.</p>
  
  <p>In table "links_clicks" are stored all the clicks and in "links" are stored the informations about each external link.</p>
  
  <p>links.id is the same with many link_clicks.link_id</p>
  
  <p>So,</p>
  
  <ol>
  <li>How do I join tables it's the first question. </li>
  <li>Related to the 1: How do i count the clicks for each link?</li>
  <li>How do i count the clicks on a link in a period of time ?</li>
  </ol>