Jump to content

ppunk

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ppunk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I should have mentioned that I am not that advanced with php (yet). I am still learning little by little. Is there anyway to explain a little more about how this can be done? You mentioned to do it as a time difference. Would it be a good idea to have the time included with the date? Right now my startDate and endDate are set up like this in my MySQL database: 2006-07-10. Any help would be great. Thanks for the reply! -Steve
  2. Hi, I am setting up an area on my site where users can post their own items they want to sell or give away, similar to a classified ad. I am having problems setting it up so it filters only active items. I want to set up the form so it allows the user to choose how many days their listing will be online (similar to ebay), like 7, 14, or 28 days as an example. After their item listing is expired, I want it so it is taken off the main site and put into an archive database table. The only way I can think of doing this is to either put the code on the main listing page so it is run everytime someone views that page, or to set up a cron job to run every once in awhile. Items don't need to be taken down immediately, so in the case of me setting up a cron job to run every 6 six hours to check for expired items would be fine. My main problem is, setting up the SQL and PHP to accomplish all this. I have had some help from some great members here, but I am still having trouble getting this to work properly and more importantly, actually learning how it works. In my items database table, here are the fields I have right now: id, startDate, endDate, type, summary (there are some more fields but they are irrelevant here). Any help or tips would be great! Thanks for any help in advance. -Steve
  3. Wow! That was a [b]terrific [/b]reply! You helped me solve all my problems!! The only thing I had to change from your example (besides two typos) was this: [code]$endDate = ($startDate - 1) + (86400 * $selDay);[/code] I did ($startDate - 1) because it was adding one too many days to the total still. By adding that it is now taking one off. So when I choose June 5th and 10 days length, it goes to June 14th. Same with the end of the month days, when I select June 25th now with a length of 10 days, it goes from June 25 to July 04. Just awesome! Do you know why it was adding an extra day to the total? Not a big deal, I am so glad it is working now! Thanks again for the great help!! -Steve
  4. Hi, I am trying to set up a page where visitors can fill out a form on my site to list their events that are going on. I saw another site that had it setup with a Start Date (month and day drop-downs) and then the length of the event (days drop-down; they had 7 days). So if I wanted to list an event starting tomorrow and have it be 4 days long, it would be like this: Start Date: June 6, 2006, Length: 4 days, so the last day would be June 9, 2006. (6, 7, 8, 9). After they fill out the form, it would get entered in the database similar to this: startDate = 2006-06-06, endDate = 2006-06-09. I was able to set this up on my own, but there were two flaws I couldn't figure out. First, one extra day was added to the total everytime. Example: I choose 2006-06-01 as start date with a length of 10 days. When it prints out the array it goes from 2006-06-02 to 2006-06-12. It should have been: 01 to 10. I am clueless here. Another problem I have found is when you choose a later day of the month and a longer length, it doesn't do anything at all. Example: I choose 2006-06-25 with a length of 10 days, it should start at 25 and go to 04 (July). It doesn't do anything. I was playing around with the day and length and found once I get to the 21st day and choose a length of 10, it doesn't work. It takes a long time to load the next page and when it does it is blank. If I go back to my form and choose the 20th with a length of 10, it works right away. I assume it has something to do with the date. There are only 30 days in June, so when I go up one more day (the 21st) and choose 10 day length, it is looking for June 31st, which doesn't exist. What is weird is that if I choose June 20th and length of 10, it prints out from June 21 to July 01 (remember, even though I chose 20 it is printing out 21 for some reason). I should also mention why I am trying to get the dates in between the Start and End Dates printed to an array. It is because I have a calendar set up and it needs the Month/Day for each day of an event in order for it to highlight the days on the calendar. I will of course have to work on getting the 'Y-m-d' formats from the array to format to 'F' and 'd' for the calendar, but that is later on. Well, here is my current code. This is the form: [code] <form id="form1" name="form1" method="get" action="form2.php"> Start Date:   <?php $curr_month = date("F"); $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $month_values = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");   echo "<select name=\"sMonth\">"; for ($i=0;$i<count($months);$i++) {     echo "<option value=\"". $month_values[$i]. "\"";     if ($curr_month==$months[$i]) { echo " selected"; }     echo ">". $months[$i]. "</option>\n"; } echo "</select>"; ?> <?php $curr_day = date("j"); $days = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"); echo "<select name=\"sDay\">"; for ($i=0;$i<count($days);$i++) {     echo "<option value=\"". $days[$i]. "\"";     if ($curr_day==$days[$i]) { echo " selected"; }     echo ">". $days[$i]. "</option>\n"; } echo "</select>"; ?> Event Length:   <select name="selDay" id="selDay">     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="10">10</option>   </select>   Days<br />   <br />   <input type="submit" name="Submit" value="Submit" /> </form> [/code] And here is the page that processes the form data and array: [code] <?php // Get Start Date and Length from form $sMonth = $_GET['sMonth']; $sDay = $_GET['sDay']; $selDay = $_GET['selDay']; // Current Year $currYear = date('Y'); // Format Start Date $sMD = "-$sMonth-$sDay"; $sYMD = $currYear.$sMD; $startDate = date('Y-m-d',strtotime($sYMD)); // Create End Date from Start Date + Length $endDate = date('Y-m-d', strtotime("$startDate+$selDay days")); // Save Dates in array - Borrowed this from another post on PHP Freaks $arrDates = array(); for ($i = $startDate; $i <= $endDate; $i++) $arrDates[] = @date('Y-m-d', strtotime($i . " days"));    // Array with 12 date-ready slots, just for testing echo $arrDates[0]; echo "<br>"; echo $arrDates[1]; echo "<br>"; echo $arrDates[2]; echo "<br>"; echo $arrDates[3]; echo "<br>"; echo $arrDates[4]; echo "<br>"; echo $arrDates[5]; echo "<br>"; echo $arrDates[6]; echo "<br>"; echo $arrDates[7]; echo "<br>"; echo $arrDates[8]; echo "<br>"; echo $arrDates[9]; echo "<br>"; echo $arrDates[10]; echo "<br>"; echo $arrDates[11]; echo "<br>"; ?> [/code] At this point, if you choose June 5th on the form with a length of 3 days, it prints out like this on the second page: [code] 2006-06-06 2006-06-07 2006-06-08 2006-06-09 [/code] I hope I explained everything clear enough. Once again, any help would be much appreciated! Thanks! -Steve
  5. First, let me say that yes my database design is weak, but it got me started. I am not too advanced with php/mysql so that is the reason why it is weak. I kinda see what your saying about setting up two tables. My only problem now is that I already tie my 'listings' table in with my 'users' table. When members login to the members area, it displays their old listings. I used INNER JOIN on the 'userid' field for both tables. If I setup my database design like you mentioned, can I connect 3 tables together? Thanks for the reply!
  6. Hi, I am still working on setting up an event listing form, and would like to know if anyone can give me any help or advice. With my site, you first have to register an account, then login to access the listing form. On the form (and in database) are the current fields: month1, day1, time1, month2, day2, time2, month3, day3, time3, type, highlight, summary The reason it is setup like month1, day1, month2, day2, month3, day3 is because it is tied in with a calendar that I setup. Which ever days are entered in the database for those fields show up on the calendar as highlighted days. That was the only way I could get it to work. It is working great now, but as I progress with my site I am finding things I would like to change. I have seen other sites that set it up like this: Start Date, and then the Number of days the event is going on for (1-7). I could leave it how it is, where the user has only 3 days available on the form, where they select the month, day, and time of each day of the event; but I thought it would be easier for the user to select the first day of the event (Start Date) and then choose how many days the event goes on for (1-7). Would something like this be easy to do? If it were possible, I then need to connect the new setup to my calendar. Right now I am storing the 3 days in my database, so it would be like this: month1 = May, day1 = 3, month2 = May, day2 = 4 The reason why the month is printed is because the calendar array is setup January-December, and if an event is near the end of a month, it would display the event day on the correct calendar month. Example: Someone posts an event for April 30th and May 1st, by using the month fields it will only show event listings on the same calendar month. If today was April 25th, then only the 30th would be highlighted on the calendar. May 1st would not be. Originally I had it setup by day only, so in the example above, the 1st and 30th would be highlighted for the month of April. That would have caused alot of confusion for visitors. I think I explained everything. Sorry about making it so long, I just wanted to include as much detail as possible. Let me know if you need more info. Any help would be great. Thanks!
  7. That worked great! I don't know what I would do without your help! I have another thing I am looking into. I will probably start another post if I can't get any leads from doing a search here or on Google. I'm looking into a way to archive old (expired) listings to another database table. I want to see if there is a way to automate it so it moves them from the listings table to the archive_listings table. Well, I gotta do some research. Thanks again for the excellent help Barand!
  8. I have a database table called 'listings' where visitors will be able to submit local event listings. The form they fill out includes the following: first_name, last_name, email, address1, address2, city, state, zip, date, time, summary. I want to setup a main listings page that organizes the listings by city. Example: Burlington (2) Springfield (5) The numbers next to the city names represent how many listings are posted for that city. I want it to filter only cities that have a listing for the current week. So if there were only two cities that had events listed for that week, it would display the above. Let's say the previous week there was a listing from the city of Hartsfield, that entry will be in the database but will be expired and should not display on the site. I actually setup the above example and got it working, but the only way I could do it was by creating a piece of code (if else statements) for each city to filter that exact city from the 'city' field in the database, and also to read the num_rows to display the number of listings in ( ). That system I setup would never work beacuse I would have to create the code for each city in the database. So basically, I would have to do every city in my state in order for my system to work. If I don't and someone posts a listing for a city that is not entered in my setup, it won't get displayed on the site at all. After spending hours on this, I finally came to my senses and decided to ask the experts. Does anyone have any ideas/suggestions for me? Is there a way to setup the programming so it detects each different city in the database and display it like my example above? I am stumped. Any help would be much appreciated. Thanks!
  9. I thought over your last post and don't think it will work for my site. While I was thinking about it I came up with this; adding a month field for each date: month1, date1, month2, date2, month3, date3, month4, date4, month5, date5 Yes, it takes up more fields in the database, but it works for me. I want to limit the amount of dates to only 5 days for one listing. I am expecting to have alot of yard sales on my site, so in most cases there will only be 2 or 3 days entered (usually Sat. and Sun.), but I'm allowing 5 days incase anyone does M-F sales. To get this to work with the calendar, I added this before the $days array: [code] $current_month = date('F'); if ($month1 == $current_month){     $day01 = $date1;     } else     echo ""; if ($month2 == $current_month){     $day02 = $date2;     } else     echo ""; if ($month3 == $current_month){     $day03 = $date3;     } else     echo "";      if ($month4 == $current_month){     $day04 = $date4;     } else     echo ""; if ($month5 == $current_month){     $day05 = $date5;     } else     echo ""; [/code] Then I changed the array to: [code] $days = array(     $day01=>array(NULL,NULL,'<div class="calendar-HL">'.$day01.'</div>'),     $day02=>array(NULL,NULL,'<div class="calendar-HL">'.$day02.'</div>'),     $day03=>array(NULL,NULL,'<div class="calendar-HL">'.$day03.'</div>'),     $day04=>array(NULL,NULL,'<div class="calendar-HL">'.$day04.'</div>'),     $day05=>array(NULL,NULL,'<div class="calendar-HL">'.$day05.'</div>'),     $today=>array(NULL,NULL,'<div class="calendarToday">'.$today.'</div>')     ); [/code] There might be a more advanced way to simplify this problem, but this is working great for me now. I might be changing it from 5 days to 3 days, so the database won't be as messy and the php cleaner. I am going to maintain the database so entries get removed often (once they expire from their entered dates) so the database doesn't get too filled up and so they don't display on the main page, because I don't want the expired events mixed in with the new/upcoming ones. I entered a couple fake entries into my database with different months/days and it filtered all accordingly. I am going to take your advice on dividing the database into two tables. I am going to create a user table with the persons name and email (might turn it into a members table instead with all contact info). I think that concludes this problem. Thanks again for the posts! -Steve
  10. Hi, thanks for the replies. In the $days array, $date1 = 31 and $date2 = 1 in my example. Whatever number is in any of the date fields (date1-date5) will get put in the correct spot in the array. That is how the dates are highlighted in green squares on my calendar. [code] $days = array(     $date1=>array(NULL,NULL,'<div class="calendar-HL">'.$date1.'</div>'),     $date2=>array(NULL,NULL,'<div class="calendar-HL">'.$date2.'</div>'),     $date3=>array(NULL,NULL,'<div class="calendar-HL">'.$date3.'</div>'),     $date4=>array(NULL,NULL,'<div class="calendar-HL">'.$date4.'</div>'),     $date5=>array(NULL,NULL,'<div class="calendar-HL">'.$date5.'</div>'),     $today=>array(NULL,NULL,'<div class="calendarToday">'.$today.'</div>')     ); [/code] With date1 and date2 pulled looks like this: [code] $days = array(     31=>array(NULL,NULL,'<div class="calendar-HL">'.31.'</div>'),     1=>array(NULL,NULL,'<div class="calendar-HL">'.1.'</div>'),     $date3=>array(NULL,NULL,'<div class="calendar-HL">'.$date3.'</div>'),     $date4=>array(NULL,NULL,'<div class="calendar-HL">'.$date4.'</div>'),     $date5=>array(NULL,NULL,'<div class="calendar-HL">'.$date5.'</div>'),     $today=>array(NULL,NULL,'<div class="calendarToday">'.$today.'</div>')     ); [/code] I hope that helps describe it better. In regards to Barand's post, do you know how I might set that up so it will pull the current year and month associated with the dates? Right now, my database table contains these: name, email, title, month, date1, date2, date3, date4, date5, time1, time2, summary Even if I didn't use the calendar I would run into problems beacuse if I displayed the full date for the event on the page it would look like this: March 31, 1 It should be like this: March 31, April 1 So my database has to be adjusted somehow because one month field is not going to work. Right now I actually don't have a 'year' field, which might be a smart idea. If I change the database fields somehow to contain the year and month for each date entered I still need it to output the day number for each day the visitor enters as 1-31 to work with that calendar array. The calendar is going to be used for a local event site, where people can post stuff like yard sales, meetings and any other kind of event. Can you think of a setup that would work? I have been thinking about your response and I can't come up with anything (yet). Thanks again for the quick replies! -Steve
  11. Hi, I have been playing around with getting a calendar on my upcoming site, and finally got it working last night. I found it at: [a href=\"http://keithdevens.com/software/php_calendar\" target=\"_blank\"]http://keithdevens.com/software/php_calendar[/a] This calendar allowed me to modify it so I can make certain days links to other pages. I didn't want links, just certain dates highlighted in another color. I did this by using an array and applying CSS styles to each one. I connected to my MySQL database and pulled dates from the selected id number. In my database, I have it setup like this: date1, date2, date3, date4, date5. I am only allowing the customer to enter up to five days, so there are 5 text fields for them to fill out. This is how it would be entered if they were having an event for the first week of April (M-F): Example: 3, 4, 5, 6, 7. I have it working so whatever dates are in the database for that id number, it grabs them and puts them in the array to display the highlighted dates on the calendar. Now here's my problem, if someone enters in dates at the end of the month, such as March 31 and April 1, it would get entered in the database as: 31, 1. On the calendar, it would highlight the 1st and the 31st of March. It should only highlight the 31st and then on the April calendar it should highlight the 1st. I have no idea how to get this to work. My guess is I have to come up with a new system for entering the dates in the database. I have been thinking of how I can fix this but can't come up with anything. I am still in the testing phase so I can add/edit/delete any of the database field names (date1, date2, etc). Here is the code for displaying the calendar (calendar2.php) [code] <?php echo "<link href=\"../css/default.css\" rel=\"stylesheet\" type=\"text/css\" />"; mysql_pconnect("localhost","myusername","mypassword"); mysql_select_db("mydatabase"); $result = mysql_query("SELECT * FROM listings WHERE ysid=6"); while ($row = mysql_fetch_array($result)) {     $date1 = $row["date1"];     $date2 = $row["date2"];     $date3 = $row["date3"];     $date4 = $row["date4"];     $date5 = $row["date5"];     $ysid = $row["ysid"]; } include 'calendar_code2.php';     $time = time();     $today = date('j',$time);     $days = array(     $date1=>array(NULL,NULL,'<div class="calendar-HL">'.$date1.'</div>'),     $date2=>array(NULL,NULL,'<div class="calendar-HL">'.$date2.'</div>'),     $date3=>array(NULL,NULL,'<div class="calendar-HL">'.$date3.'</div>'),     $date4=>array(NULL,NULL,'<div class="calendar-HL">'.$date4.'</div>'),     $date5=>array(NULL,NULL,'<div class="calendar-HL">'.$date5.'</div>'),     $today=>array(NULL,NULL,'<div class="calendarToday">'.$today.'</div>')     );     echo generate_calendar(date('Y', $time), date('n', $time), $days); ?> [/code] And here is the code that makes the calendar work (calendar_code2.php): [code] <?php # PHP Calendar (version 2.3), written by Keith Devens # http://keithdevens.com/software/php_calendar #  see example at http://keithdevens.com/weblog # License: http://keithdevens.com/software/license function generate_calendar($year, $month, $days = array(), $day_name_length = 1, $month_href = NULL, $first_day = 0, $pn = array()){     $first_of_month = gmmktime(0,0,0,$month,1,$year);     #remember that mktime will automatically correct if invalid dates are entered     # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998     # this provides a built in "rounding" feature to generate_calendar()     $day_names = array(); #generate all the day names according to the current locale     for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday         $day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name     list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));     $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day     $title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names     #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03     @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable     if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';     if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';     $calendar = '<table class="calendar" cellspacing=\"0\" cellpadding=\"3\">'."\n".         '<caption class="calendarHeader">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr class=\"calendarHeader2\">";     if($day_name_length){ #if the day names should be shown ($day_name_length > 0)         #if day_name_length is >3, the full name of the day will be printed         foreach($day_names as $d)             $calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';         $calendar .= "</tr>\n<tr>";     }     if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days     for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){         if($weekday == 7){             $weekday   = 0; #start a new week             $calendar .= "</tr>\n<tr>";         }         if(isset($days[$day]) and is_array($days[$day])){             @list($link, $classes, $content) = $days[$day];             if(is_null($content))  $content  = $day;             $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').                 ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';         }         else $calendar .= "<td>$day</td>";     }     if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days     return $calendar."</tr>\n</table>\n"; } ?> [/code] Here is a working example of the calendar that shows the mentioned problem: [a href=\"http://honolulu.micfo.com/~lobster/cal/local_listings/calendar2.php\" target=\"_blank\"]http://honolulu.micfo.com/~lobster/cal/loc...s/calendar2.php[/a] Any help would be much appreciated! Thanks! -Steve
×
×
  • 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.