Skip to main content
  • Home
  • Tags
OpenView360
Think Smart, Be Free, Choose Open Source
Home

php

Simple PHP Calendar

In:
  • calendar
  • coding
  • php
12Nov2009

I was searching today for a pre-made script for a simple php calendar and after a bit of search I've found this.

The code is a bit old, and the author's website doesn't seem to work anymore, so I decided to clean it up a bit.
You can see the result below.

  1. <?php
  2. // This gets today's date
  3. $date = time ();
  4.  
  5. // This puts the day, month, and year in seperate variables
  6. $day  = date('d', $date);
  7. $month= date('m', $date);
  8. $year = date('Y', $date);
  9.  
  10. // Here we generate the first day of the month
  11. $first_day = mktime(0,0,0,$month, 1, $year);
  12.  
  13. //This gets us the month name
  14. $title = date('F', $first_day);
  15.  
  16. //Here we find out what day of the week the first day of the month falls on
  17. $day_of_week = date('D', $first_day);
  18.  
  19. //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
  20. switch($day_of_week) {
  21.   case "Sun": $blank = 0; break;
  22.   case "Mon": $blank = 1; break;
  23.   case "Tue": $blank = 2; break;
  24.   case "Wed": $blank = 3; break;
  25.   case "Thu": $blank = 4; break;
  26.   case "Fri": $blank = 5; break;
  27.   case "Sat": $blank = 6; break;
  28. }
  29.  
  30. // We then determine how many days are in the current month
  31. $days_in_month = cal_days_in_month(0, $month, $year);
  32. ?>
  33.  
  34. <table cellpadding="0" cellspacing="0">
  35.   <tr>
  36.     <th colspan="7"><?php print $month; ?> <?php print $year; ?></th>
  37.   </tr>
  38.   <tr>
  39.     <td>Sun</td>
  40.     <td>Mon</td>
  41.     <td>Tue</td>
  42.     <td>Wed</td>
  43.     <td>Thu</td>
  44.     <td>Fri</td>
  45.     <td>Sat</td>
  46.   </tr>
  47.    <?php $day_count = 1;// This counts the days in the week, up to 7 ?>
  48.   <tr>
  49.   <?php while ($blank > 0): //first we take care of those blank days ?>
  50.     <td>&nbsp;</td> <?php $blank = $blank-1; $day_count++; ?>
  51.   <?php endwhile; ?>
  52.   <?php $day_num = 1; //sets the first day of the month to 1 ?>  
  53.  
  54.   <?php while ($day_num <= $days_in_month): //count up the days, until we've done all of them in the month ?>
  55.     <td><?php print $day_num; ?></td>
  56.     <?php $day_num++; $day_count++; ?>
  57.     <?php if ($day_count > 7): //Make sure we start a new row every week ?>
  58.   </tr>
  59.   <tr>
  60.     <?php $day_count = 1; ?>
  61.     <?php endif; ?>
  62.   <?php endwhile; ?>
  63.    
  64.   <?php while ($day_count >1 && $day_count <=7): //Finaly we finish out the table with some blank details if needed ?>
  65.     <td>&nbsp;</td>
  66.     <?php $day_count++; ?>
  67.   <?php endwhile; ?>
  68.   </tr>
  69. </table>

  • CoolGoose's blog
  • Add new comment

Simple PHP Tag Cloud (CodeIgniter)

In:
  • codeigniter
  • php
  • tag cloud
28Aug2008

Here's my simple tagCloud Codeigniter php script
video_to_tag table is a many_to_many relationship table.

I know that this code can be improved but right now it's a nice starting point.

  1. public function tagCloud($nr_entries)
  2. {
  3.  
  4.     $this->db->select('COUNT(video_to_tag.tag_id) as tag_entries,
  5.  
  6.                       tags.tag_name')
  7.  
  8.              ->from('video_to_tag')
  9.  
  10.              ->join('tags', 'tags.tag_id = video_to_tag.tag_id', 'inner')
  11.  
  12.              ->group_by('tags.tag_name')
  13.  
  14.              ->order_by('tags.tag_id')
  15.  
  16.              ->limit($nr_entries,0);   
  17.  
  18.     $result = $this->db->get();
  19.  
  20.    
  21.  
  22.     if (0 < $result->num_rows())
  23.     {
  24.  
  25.         $result = $result->result();
  26.  
  27.         $tags = array();
  28.        
  29.         // order the tags array
  30.  
  31.         foreach ($result as $entry)
  32.         {
  33.             $tags[$entry->tag_name] = $entry->tag_entries;
  34.         }            
  35.  
  36.  
  37.  
  38.         $max_size = 250; // max font size in %
  39.  
  40.         $min_size = 100; // min font size in %
  41.  
  42.  
  43.  
  44.         // get the largest and smallest array values
  45.  
  46.         $max_qty = max(array_values($tags));
  47.  
  48.         $min_qty = min(array_values($tags));
  49.  
  50.  
  51.  
  52.         // find the range of values
  53.  
  54.         $spread = $max_qty - $min_qty;
  55.  
  56.         if (0 == $spread) // we don't want to divide by zero
  57.         {
  58.             $spread = 1;
  59.         }
  60.  
  61.  
  62.  
  63.         // determine the font-size increment
  64.  
  65.         // this is the increase per tag quantity (times used)
  66.  
  67.         $step = ($max_size - $min_size)/($spread);
  68.  
  69.        
  70.  
  71.         // init the url helper
  72.  
  73.         $this->load->helper('url');
  74.  
  75.         // init the tag cloud
  76.  
  77.         $tag_cloud = '';
  78.  
  79.         // loop through our tag array
  80.  
  81.         foreach ($tags as $key => $value)
  82.         {
  83.             // calculate CSS font-size
  84.  
  85.             // find the $value in excess of $min_qty
  86.  
  87.             // multiply by the font-size increment ($size)
  88.  
  89.             // and add the $min_size set above
  90.  
  91.             $size = $min_size + (($value - $min_qty) * $step);
  92.  
  93.  
  94.  
  95.             $url_attributes = array('title' => "{$value} things tagged with {$key}",
  96.  
  97.                                     'style' => "font-size: {$size}%");
  98.  
  99.             $tag_cloud .= anchor('tag/'.url_title($key), $key, $url_attributes) . '&nbsp;';
  100.  
  101.          }
  102.  
  103.          
  104.  
  105.          return $tag_cloud;
  106.  
  107.  
  108.  
  109.     }  
  110.  
  111.     return false;              
  112.  
  113. }

  • CoolGoose's blog
  • Add new comment
Entries (RSS)

About

Just your average goose.

Activity Stream

  • Fri, 12/03/2010 - 00:26

  • Digg CoolGoose dugg Why you'll never be able to legally rip your DVDs 12:26am#
  • Digg CoolGoose dugg Google's Own Stated List of Competitors Grows from 2 to 10 11:54pm#
  • Digg CoolGoose dugg Mozilla Wants You To Help Rewrite Its Public License 11:54pm#
  • Digg CoolGoose dugg Commercial Gaming, Coming Soon to Linux? 11:54pm#
  • Digg CoolGoose dugg Why (I think) Ubuntu is Better Than Windows 11:29pm#
  • Digg CoolGoose dugg Android Crushes the Competition, iPhone Stands Still 11:28pm#
  • Digg CoolGoose dugg The Reasons Why Your Boss is Always Right 10:48pm#
  • Digg CoolGoose dugg CNET: Android phones get Opera Mini 5 beta 10:34pm#

Tags in Tags

boris akunin carti css demon design devils digg erast fandorin gand general gnome iubire joey goebel kde linux love melancolie open source party php plugins poem power user problem protest quest random random thoughts regex regina noptii remorse renastere site tristete ubuntu windows
more tags

Search

Community

belletristisch.com - Online Literature
OS Revolution - Living in a matrix
At-byte.com - Stay Sharp
Linux PHP IDE

Who's online

There are currently 0 users and 1 guest online.

Syndicate

Syndicate content
Copyright alexandrubucur.com

Drupal port by 3rdWorld : Created by Design Disease