title: MYSQL - Query items that match date
body: <p>I'm making a Calendar in PHP, and I have a for loop for 31 days (or depending on how many days are in the month), each day is written out with $listDay. </p>
  
  <p>In my MySQL database, I have a field called 'eventDate' with a unix timestamp, and I have a variable $event_day built from the timestamp just for the day. I can't figure out how to write a query that says "If $listDay == $event_day then show this". This code might be a little messy because i've been playing around with a bunch of options.</p>
  
  <p>What this is supposed to do is if there is an event that day, replace the standard number with a link, which if moused over will show a little popup of the event (that is handled in js, and i do have the popup working correctly)</p>
  
  <p>I know something is wrong with the way I have the MySQL statements, but I can't quite figure it out. Oh yeah, I created a field in the db called 'eventMonth', since I couldn't figure how to make the query 'match' a month with the timestamp.</p>
  
  <pre><code>$month = date("F");
  $vmonth = date("n");
  $current_month = date("n"); //value will change if the user changes the month they are viewing
  $current_year = date('Y');
  $theday = date(w, mktime(0, 0, 0, $current_month, 1, $current_year));
  $daysinmonth = date("t", mktime(0, 0, 0, $current_month, 1, $current_year));
  
  echo "&lt;table bgcolor=\"#C68282\" style=\"border: #990000 1px solid; font-size:8pt; font-family: Tahoma; color: #000000\" cellpadding=\"1\" cellspacing=\"0\" width=\"129\"&gt;";
  echo "&lt;tr&gt;
  &lt;td colspan=7 align=center style=\"font-weight: bold;\"&gt;".date('F Y', mktime(0, 0, 0, $current_month, 1, $current_year))."&lt;/td&gt;
  &lt;/tr&gt;";
  echo "&lt;tr style=\"background-color: 990000; color: white;\"&gt;";
  echo "&lt;td align=center&gt;S&lt;/td&gt;";
  echo "&lt;td align=center&gt;M&lt;/td&gt;";
  echo "&lt;td align=center&gt;T&lt;/td&gt;";
  echo "&lt;td align=center&gt;W&lt;/td&gt;";
  echo "&lt;td align=center&gt;T&lt;/td&gt;";
  echo "&lt;td align=center&gt;F&lt;/td&gt;";
  echo "&lt;td align=center&gt;S&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  echo "&lt;tr&gt;";
  for ($i=0;$i&lt;$theday;$i++)
  {
     echo "&lt;td&gt;&amp;nbsp;&lt;/td&gt;";
  }
  $query = "SELECT * FROM calendar WHERE eventMonth = '77'"; 
  $result = mysql_query($query); 
  $row = mysql_fetch_array($result);
  for ($list_day=1;$list_day&lt;=$daysinmonth;$list_day++)
  {
      $event_day = date('j',$row['eventDate']);
    echo "&lt;td align=\"center\"&gt;";
    if($list_day == $event_day) { 
      echo "&lt;a href=\"#\" class=\"cal\"&gt;";
          echo $list_day . "&lt;span class\"cal\"&gt;&lt;div style=\"border-bottom: 1px solid #999999; padding: 2px; \"&gt;" . $month ."&amp;nbsp;". $list_day .",&amp;nbsp;". $current_year ." &lt;/div&gt;&lt;div style=\"padding: 2px;\"&gt;" . $row['event'] ."&lt;/div&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;";
      } else { 
          echo $list_day;
      }
    if ($theday == 6)
    {
      echo "&lt;/tr&gt;";
      echo "&lt;tr&gt;";
      $theday = -1;
    }
    $theday++;
  }
  echo "&lt;/tr&gt;";
  echo "&lt;/table&gt;";
  </code></pre>