Jump to content

lukelambert

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lukelambert's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry bpops, I haven't checked back here in a while. I completely overlooked the fact that it would not increase the post count the first time they visit (which will probably be the only time on individual items so that code was completely useless). I think I have fixed it now though. [code]<?php $cc_name = "counter"; // Name of the cookie $cc_expires = time() + 3600; // Expires in an hour $cc_item = "[" . $_GET['id'] . "]"; // Item identifier in [XX] format $cc_inc = false; // Whether the number of hits for that item should be incremented. if ($_COOKIE[$cc_name]) { $cc_value = $_COOKIE[$cc_name]; if (strpos($cc_value, $cc_item) === false) // If the user has not visited this page { $cc_value .= $cc_item; // Add the item to the cookie $cc_inc = true; } } else { $cc_value = $cc_item; // Add the item to the cookie $cc_inc = true; } if ($cc_inc) { // Increase view count in database or whatever here // Something like: mysql_query("UPDATE item_table SET (hits = hits + 1) WHERE (id = " . $_GET['id'] . ")", $connection); } setcookie($cc_name, $cc_value, $cc_expires); // Create or re-create the cookie ?>[/code]
  2. The table was created by a third party product. It is already populated with data and I don't intend on altering it. Yes, I agree that your solution would by far be the easiest way, but I am not looking for a new solution. I need to know why my code is not working. If there are 86400 seconds in one day and 3024000 in 35 days shouldn't that math work out?
  3. Try arsort($data);. That will keep the keys intact. http://us2.php.net/manual/en/function.arsort.php
  4. I don't want events only in November. I want from October 29 to December 2. Yes I could SELECT * FROM table WHERE timestamp BETWEEN '20061029000000' AND '20061203000000' but the 'timestamp' column is int(11).
  5. Or if you just want to use a cookie... [code] <?php $cc_name = "counter"; // Name of the cookie $cc_expires = time() + 3600; // Expires in an hour $cc_item = "[" . $_GET['id'] . "]"; // Item identifier in [XX] format if ($_COOKIE[$cc_name]) { $cc_value = $_COOKIE[$cc_name]; if (strpos($cc_value, $cc_item) === false) // If the user has not visited this page { // Increase view count in database or whatever here // Something like: mysql_query("UPDATE item_table SET (hits = hits + 1) WHERE (id = " . $_GET['id'] . ")", $connection); $cc_value .= $cc_item; // Add the item to the cookie } } else $cc_value = $cc_item; // Add the item to the cookie setcookie($cc_name, $cc_value, $cc_expires); // Create or re-create the cookie ?> [/code] Basically everytime the user loads the page, this code scans the cookie to see if they have been here or not according to the item id. Also, the cookie refreshes everytime the user visits a new item so the expiration time is always updating. You would need to have a hits column in your item_table (or whatever it's named). In addition, $connection should be your actual database connection. I don't know if there is a length limit on cookies but this one might get a little long if the user is visiting a lot of pages.
  6. I wrote a script to display the days of a selected month in calendar form (4, 5 or 6 rows by 7 columns). I wanted the days of the previous and next months to fill the empty cells on the calendar before and after the days in the selected month. For example, the calendar for November 2006 would look like this: [table] [tr] [td]Sun[/td] [td]Mon[/td] [td]Tue[/td] [td]Wed[/td] [td]Thu[/td] [td]Fri[/td] [td]Sat[/td] [/tr] [tr] [td][color=gray]29[/color][/td] [td][color=gray]30[/color][/td] [td][color=gray]31[/color][/td] [td]1[/td] [td]2[/td] [td]3[/td] [td]4[/td] [/tr] [tr] [td]5[/td] [td]6[/td] [td]7[/td] [td]8[/td] [td]9[/td] [td]10[/td] [td]11[/td] [/tr] [tr] [td]12[/td] [td]13[/td] [td]14[/td] [td]15[/td] [td]16[/td] [td]17[/td] [td]18[/td] [/tr] [tr] [td]19[/td] [td]20[/td] [td]21[/td] [td]22[/td] [td]23[/td] [td]24[/td] [td]25[/td] [/tr] [tr] [td]26[/td] [td]27[/td] [td]28[/td] [td]29[/td] [td]30[/td] [td][color=gray]1[/color][/td] [td][color=gray]2[/color][/td] [/tr] [/table] The display part is working perfectly but now I want to select events from an SQL table that have a timestamp that is greater than or equal to the first day on the calendar at 12:00 am and less than one day after the last day on the calendar at 12:00 am. In other words, I want the events that take place between the beginning and end of the calendar. Anyway, here is my code... [code] $month = 11; // Let's say the selected month is November 2006 $year = 2006; $month_days = array( // The number of days in each month     1 => 31,     2 => 28,     3 => 31,     4 => 30,     5 => 31,     6 => 30,     7 => 31,     8 => 31,     9 => 30,     10 => 31,     11 => 30,     12 => 31 ); if (date("L", mktime(0, 0, 0, 1, 1, $year))) // Determines if it is a leap year     $month_days[2] = 29; $day_of_week = date("w", mktime(0, 0, 0, $month, 1, $year)); // The day of the week of the first day of the month $num_rows = ceil(($month_days[$month] + $day_of_week) / 7); // Number of seven cell rows $timestamp_begin = date("U", mktime(0, 0, 0, $month, 1, $year)) - $day_of_week * 86400; /* The timestamp of the first day of the month minus (the number of days before the month begins times the number of seconds in a day) */ $timestamp_end = $timestamp_begin + $num_rows * 7 * 86400; /* The timestamp of the first day on the calendar plus (the number of cells times the number of seconds in a day) */ echo $timestamp_begin . " = " . date("F d, Y H:i:s", $timestamp_begin) . "<br />"; echo $timestamp_end . " = " . date("F d, Y H:i:s", $timestamp_end); [/code] This prints [code] 1162101600 = October 29, 2006 01:00:00 1165125600 = December 03, 2006 00:00:00 [/code] On some months it works perfectly and on others it is an hour off on either $timestamp_begin or $timestamp_end. Am I doing something wrong or is this a bug? I am running PHP Version 5.1.2 on Mac OS X 10.4.7.
×
×
  • 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.