Jump to content

Need help on counting number of times this data appears


farban6

Recommended Posts

if ($month <= 9){
      	
  if ($list_day <= 9){
      $event_day = $year.'-'."0".$month.'-'."0".$list_day;
      if(isset($events[$event_day])) {
        foreach($events[$event_day] as $event) {
          $calendar.= '<div class="event">'.$event['event_date'].'</div>';
        }
      }
  }

 

Right, using a mysql query the value from $event['event_Date'] prints out in a div. I need a number count of the amount of times this value is printed. any help?

 

 

Link to comment
Share on other sites

Yeah i tried to use a for loop but i couldnt get the number to increment once, I want a single number to count to 3 if there are 3 instances of the date 10-10-2011, rather than 1,1,1. Plus i cant get the number to fit into the div despite the fact the varible is inside the div

 

 

calender.php

 

<script type="text/javascript">

function popup(v) {
window.open('dayview.php?event_date='+ v,'_blank','width=800,height=600');
}

</script>

<?php
   /* draws a calendar */
function draw_calendar($month,$year,$events = array()){

  /* draw table */
  $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';

  /* table headings */
  $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';

  /* days and weeks vars now ... */
  $running_day = date('w',mktime(0,0,0,$month,1,$year));
  $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
  $days_in_this_week = 1;
  $day_counter = 0;
  $dates_array = array();

  /* row for week one */
  $calendar.= '<tr class="calendar-row">';

  /* print "blank" days until the first of the current week */
  for($x = 0; $x < $running_day; $x++):
    $calendar.= '<td class="calendar-day-np"> </td>';
    $days_in_this_week++;
  endfor;

  /* keep going with days.... */
  for($list_day = 1; $list_day <= $days_in_month; $list_day++):
  
  $count = array();
  $count = 
    $calendar.= "<td class='calendar-day'><div style='position:relative;height:100px;' onclick=\"popup('".$year.'-'.$month.'-'.$list_day."')\">";
      /* add in the day number */
      $calendar.= '<div class="day-number">'.$list_day.'</div>';
  
      if ($month <= 9){
      	
  if ($list_day <= 9){
      $event_day = $year.'-'."0".$month.'-'."0".$list_day;
      if(isset($events[$event_day])) {
        foreach($events[$event_day] as $event) {
          $calendar.= '<div class="event">'.$event['event_date'].'</div>';
        }
      }
  }
  
  if ($list_day >= 10) {
      $event_day = $year.'-'."0".$month.'-'.$list_day;
      if(isset($events[$event_day])) {
        foreach($events[$event_day] as $event) {
          $calendar.= '<div class="event">'.$event['event_date'].'</div>';
        }
      }
  }
  
  }
  if ($month >= 10){
  	
  if ($list_day <= 9){
      $event_day = $year.'-'.$month.'-'."0".$list_day;
      if(isset($events[$event_day])) {
        foreach($events[$event_day] as $event) {
        	$count =+ 1;
		echo $count;
		$calendar.= '<div class="event">'.$event['event_date'].'</div>';        
	}
      }
  }
  
  if ($list_day >= 10) {
      $event_day = $year.'-'.$month.'-'.$list_day;
      if(isset($events[$event_day])) {
        foreach($events[$event_day] as $event) {
			$calendar.= '<div class="event">'.$event['event_date'].'</div>';          }
      }
  }
  
  }
      else {
        $calendar.= str_repeat('<p> </p>',2);
      }
    $calendar.= '</div></td>';
    if($running_day == 6):
      $calendar.= '</tr>';
      if(($day_counter+1) != $days_in_month):
        $calendar.= '<tr class="calendar-row">';
      endif;
      $running_day = -1;
      $days_in_this_week = 0;
    endif;
    $days_in_this_week++; $running_day++; $day_counter++;
  endfor;

  /* finish the rest of the days in the week */
  if($days_in_this_week < :
    for($x = 1; $x <= (8 - $days_in_this_week); $x++):
      $calendar.= '<td class="calendar-day-np"> </td>';
    endfor;
  endif;

  /* final row */
  $calendar.= '</tr>';
  

  /* end the table */
  $calendar.= '</table>';

  /** DEBUG **/
  $calendar = str_replace('</td>','</td>'."\n",$calendar);
  $calendar = str_replace('</tr>','</tr>'."\n",$calendar);
  
  /* all done, return result */
  return $calendar;
}
?>

 

index.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Conforming XHTML 1.0 Strict Template</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link type="text/css" href="ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>


</head>

<body>
<script type="text/javascript">
$('#date').datepicker();
$('#time').timepicker({});
</script>



<?php


include_once("functions/database.php");
include_once("functions/calender.php");
include_once("functions/number.php");

include_once("pending.php");





/* date settings */
$month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));
$year = (int)  ($_GET['year'] ? $_GET['year'] : date('Y'));

/* select month control */
$select_month_control = '<select name="month" id="month">';
for($x = 1; $x <= 12; $x++) {
  $select_month_control.= '<option value="'.$x.'"'.($x != $month ? '' : ' selected="selected"').'>'.date('F',mktime(0,0,0,$x,1,$year)).'</option>';
}
$select_month_control.= '</select>';

/* select year control */
$year_range = 7;
$select_year_control = '<select name="year" id="year">';
for($x = ($year-floor($year_range/2)); $x <= ($year+floor($year_range/2)); $x++) {
  $select_year_control.= '<option value="'.$x.'"'.($x != $year ? '' : ' selected="selected"').'>'.$x.'</option>';
}
$select_year_control.= '</select>';

/* "next month" control */
$next_month_link = '<a href="?month='.($month != 12 ? $month + 1 : 1).'&year='.($month != 12 ? $year : $year + 1).'" class="control">Next Month >></a>';

/* "previous month" control */
$previous_month_link = '<a href="?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'" class="control"><<   Previous Month</a>';


/* bringing the controls together */
$controls = '<form method="get">'.$select_month_control.$select_year_control.' <input type="submit" name="submit" value="Go" />      '.$previous_month_link.'     '.$next_month_link.' </form>';

/* get all events for the given month */
$events = array();


$query = "SELECT * FROM events WHERE status ='approved' ORDER BY event_time" or die (mysql_error());


$result = mysql_query($query, $db_link) or die('cannot get results!');
while($row = mysql_fetch_assoc($result)) {
  $events[$row['event_date']][] = $row;
}

echo '<h2 style="float:left; padding-right:30px;">'.date('F',mktime(0,0,0,$month,1,$year)).' '.$year.'</h2>';
echo '<div style="float:left;">'.$controls.'</div>';
echo '<div style="clear:both;"></div>';
echo draw_calendar($month,$year,$events);
echo '<br /><br />';

?>



</body>
</html>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.