Hi, I am building this script to display a daily comic, I am trying to get every day after the start date and up to the present date to turn into a link on the calendar but only those days. The script is more than one file but I believe the error is in this file. There shouldn't be any dependencies you need to know about. The script is located at http://www.frontandcover.com/comic/ so you can see what I'm looking at.

<?php include 'top.html' ?>
<?php
//Maintenance Message
echo "<table div align=center border=1 bordercolor=yellow><td border=1 bordercolor=yellow bgcolor=#CCCCCC><p><b>Administrator Message:<b> <br>Some maintenance on this script is in progress. Some errors may appear during this time.</p></td></table>";

date_default_timezone_set('EST');
//set start date to the same thing in index.php & getimage.php
$lowerlimitday=19;
$lowerlimitmonth=10;
$lowerlimityear=2012;

function compareDates($firstyear,$firstmonth,$firstday,$secondyear,$secondmonth,$secondday){
if($firstyear==$secondyear){
     if($firstmonth==$secondmonth){
        if($firstday==$secondday){
        //first date is equal to second date
        return 0;
        }
        if($firstday>$secondday){
        //first date is greater than second date
        return 1;
        }
        if($firstday<$secondday){
        //first date is less than second date
        return -1;
        }
     }
     if($firstmonth>$secondmonth){
     //first date is greater than second date
    return 1;

     }
     if($firstmonth<$secondmonth){
     //first date is less than second date
    return -1;
     }
}
if($firstyear>$secondyear){
//first date is greater than second date
return 1;
}
if($firstyear<$secondyear){
//first date is less than second date
return -1;
}
}

if(strlen($imagename)<1){
$imagename = date(DATE_ATOM);
$imagename = mb_substr($imagename,0,10);
$today = mb_substr($imagename,8,2);
$thismonth = mb_substr($imagename,5,2);
$thisyear = mb_substr($imagename,0,4);
}
$year =$_GET['year'];
if(strlen($year)!=4){ echo "<br>please make sure you entered a year. if you entered no year, the system will enter the year as this year";
$year=$thisyear;
}
$month =$_GET['month'];
if(strlen($month)!=2){ echo "<br>please make sure you entered a month. if you entered no month, the system will enter the month as this month";
$month=$thismonth;}
$day =$_GET['day'];
if(strlen($day)!=2){ echo $day; $day=$today;}
?>

<center><img src="getimage.php?date=<?php echo $year; echo "-"; echo $month; echo "-"; echo $day; ?>"></center>
<?php
$daymax=0;

if($month<13 && $month>0){
$daymax = cal_days_in_month(CAL_GREGORIAN, $month, $year);
}
?>
<div align=center><table><td width=1>
<br>
<form action="index.php" method="post">
<br><br>
<SELECT NAME="year">
<OPTION VALUE="">Choose Year
<OPTION VALUE="2012">2012
<OPTION VALUE="2013">2013
<OPTION VALUE="2014">2014
<OPTION VALUE="2015">2015
<OPTION VALUE="2016">2016
<OPTION VALUE="2017">2017
<OPTION VALUE="2018">2018
<OPTION VALUE="2019">2019
</SELECT>
<SELECT NAME="month">
<OPTION VALUE="">Choose Month
<OPTION VALUE="01">January
<OPTION VALUE="02">February
<OPTION VALUE="03">March
<OPTION VALUE="04">April
<OPTION VALUE="05">May
<OPTION VALUE="06">June
<OPTION VALUE="07">July
<OPTION VALUE="08">August
<OPTION VALUE="09">September
<OPTION VALUE="10">October
<OPTION VALUE="11">November
<OPTION VALUE="12">December
</SELECT>

<br>
<br><input type="submit" /><br><br>
<?php 
if($month==01){ echo " January "; echo $year; }
elseif($month==02){ echo " February "; echo $year; }
elseif($month==03){ echo " March "; echo $year; }
elseif($month==04){ echo " April "; echo $year; }
elseif($month==05){ echo " May "; echo $year; }
elseif($month==06){ echo " June "; echo $year; }
elseif($month==07){ echo " July "; echo $year; }
elseif($month==08){ echo " August "; echo $year; }
elseif($month==09){ echo " September "; echo $year; }
elseif($month==10){ echo " October "; echo $year; }
elseif($month==11){ echo " November "; echo $year; }
elseif($month==12){ echo " December "; echo $year; }
echo("<table border=1>");
echo("<tr> <td>Sun</td> <td>Mon</td> <td>Tue</td> <td>Wed</td> <td>Thu</td> <td>Fri</td> <td>Sat</td> </tr>");
//<tr> emit
$formatCounter=1;
 $h = mktime(0, 0, 0, $month, 1, $year);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 if($w=="Sunday"){
 echo "<tr>";
  $formatCounter--;
 }
 if($w=="Monday"){
 echo "<tr>";
 echo "<td width=0 bgcolor=FFFFFF></td>";
 }
  if($w=="Tuesday"){
 echo "<tr>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 $formatCounter++;
 }
  if($w=="Wednesday"){
   echo "<tr>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 $formatCounter++;
 $formatCounter++;

 }
  if($w=="Thursday"){
   echo "<tr>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 $formatCounter++;
 $formatCounter++;
 $formatCounter++;
 }
  if($w=="Friday"){
 echo "<tr>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 $formatCounter++;
 $formatCounter++;
 $formatCounter++;
 $formatCounter++;
 }
  if($w=="Saturday"){
 echo "<tr>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 $formatCounter++;
 $formatCounter++;
 $formatCounter++;
 $formatCounter++;
 $formatCounter++;
 } 
 $isDay=true;
for ( $counter = 1; $counter <= $daymax; $counter += 1) {
//the nine vars: $thisyear, $year (the year entered), $lowerlimityear, $thismonth, $month (the month entered), $lowerlimitmonth, $thisday, $day (the day entered), $lowerlimitday

if((compareDates($lowerlimityear,$lowerlimitmonth,$lowerlimitday,$year,$month, $day)==-1 ) && (compareDates($year,$month,$day,$thisyear,$thismonth,$thisday)==-1))
 { 
 $isDay=true;
 echo "On "; 
 }


if((compareDates($lowerlimityear,$lowerlimitmonth,$lowerlimitday,$year,$month, $day)==1) || (compareDates($year,$month,$day,$thisyear,$thismonth,$thisday)==1))
{ 
$isDay=false;
echo "Off "; 
}



$formatCounter++;
 $h = mktime(0, 0, 0, $month, $counter, $year);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
if($formatCounter == 8 || $formatCounter == 15 || $formatCounter == 22 || $formatCounter == 29){echo("<tr>");}
    echo "<td width=1 bgcolor=CCCCCC>";
    if($isDay){
    echo "<a href=index.php?year=";
    echo $year;
    echo "&month=";
    echo $month;
    echo "&day=";
    } else { echo $counter; }
if($counter<10){ 
if($isDay){
    if($counter==1){echo "01";}
    if($counter==2){echo "02";}
    if($counter==3){echo "03";}
    if($counter==4){echo "04";}
    if($counter==5){echo "05";}
    if($counter==6){echo "06";}
    if($counter==7){echo "07";}
    if($counter==8){echo "08";}
    if($counter==9){echo "09";}
    }
}
if(10 <= $counter){ if($isDay){echo $counter;} }
    if($isDay){
    echo " >";
    echo $counter;
    echo "</a>";
    echo "</td>";
    }
if($formatCounter == 7 || $formatCounter == 14 || $formatCounter == 21 || $formatCounter == 28 || $formatCounter == 35){echo("</tr>");}
}
 $h = mktime(0, 0, 0, $month, $daymax, $year);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 if($w=="Sunday"){
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "</tr>";
 }
 if($w=="Monday"){
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "</tr>";
 }
  if($w=="Tuesday"){
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "</tr>";
 }
  if($w=="Wednesday"){
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "</tr>";
 }
  if($w=="Thursday"){
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "</tr>";
 }
  if($w=="Friday"){
 echo "<td width=1 bgcolor=CCCCCC>&nbsp;&nbsp;</td>";
 echo "</tr>";
 }
  if($w=="Saturday"){
 echo "</tr>";
 } 
echo("</table>");
?>
<p></p>
<?php include '../foot.html' ?>

Recommended Answers

All 14 Replies

For some reason I can't edit this from my device. It occured to me that maybe this question is asking too much.

Member Avatar for LastMitch

I am trying to get every day after the start date and up to the present date to turn into a link on the calendar but only those days. The script is more than one file but I believe the error is in this file.
For some reason I can't edit this from my device. It occured to me that maybe this question is asking too much.

My question is what error do you get? The link doesn't really help much. You just want to update all the comic strip til now? I assume you have a db and a table created?

Okay, let me try to improve my explanation. I have a subdirectory that holds gif images each named in the format YYYY-MM-DD.gif and has permissions 640 for security. There is also a script that copies each image from the folder and is designed not to output any image that is named with a date later than today's date or the starting date. That allows the cartoonist to set and forget comics in advance. The file you are looking at mirrors that design philosophy but for the GUI. By default it sends a request to the first script to output the comic file with the code <img src=getimage.php?date=YYYY-MM-DD

What you can see from the webpage, the script is returning todays image. However, the script has additional functionality. It is supposed to render a calendar with the correct formatting for each month and turn each number between the start date (see the $lowerlimit variables) and today's date into a link which changes the variables to output the selected day's comic. There are three interrelated problems:
1. The script is not correctly turning calendar numbers into links. Right now its the third, but there arent any links.
2. Trying to use the option drop-down fails to change the calendar. It appears the variables are being reset. Because I cannot change the month I can't check to see if the correct links are rendered for other months.
3. Manually typing a URL in the format that the links would into the address bar of my browser doesn't seem to change the image viewed or the calendar to correspond with the associated date.

Member Avatar for LastMitch
  1. The script is not correctly turning calendar numbers into links. Right now its the third, but there arent any links.
  2. Trying to use the option drop-down fails to change the calendar. It appears the variables are being reset. Because I cannot change the month I can't check to see if the correct links are rendered for other months.
  3. Manually typing a URL in the format that the links would into the address bar of my browser doesn't seem to change the image viewed or the calendar to correspond with the associated date.

This is more than just an debugging. It's more like work! This is more than 1 file. I know that for sure. You might have to used CURL for #1 & #3. #2 seems right meaning it's less work than the other 2! I can tell you now I can only do 1 out of 3. You have to figure out the other 2 yourself or someone have to help you with the other 2. The code that you posted above is actually #2. What error are you getting now?

commented: helpful beyond just the script itself +1
commented: To Rectify what some retard did to LastMitch +0

Oh, no problem. Sorry, to bother you. I'm pretty much a novice, so I don't have a good sense about where the line is between something that a more experienced person can just eyeball and something that would take anyone considerable time. Actually your comment "This is more than just an debugging. It's more like work!" is probably more useful to me than even having a solution to the problems in my script because it helps me get a sense of what level of work and the kinds of issues I might encounter in the future if I decide to design software professionally. You mean PHP cURL? Thanks I'll look into that.

Member Avatar for LastMitch

@Goldfinch

Oh, no problem. Sorry, to bother you. I'm pretty much a novice, so I don't have a good sense about where the line is between something that a more experienced person can just eyeball and something that would take anyone considerable time. Actually your comment "This is more than just an debugging. It's more like work!" is probably more useful to me than even having a solution to the problems in my script because it helps me get a sense of what level of work and the kinds of issues I might encounter in the future if I decide to design software professionally. You mean PHP cURL? Thanks I'll look into that.

I wasn't trying being rude or mean. I mean you have to understand Daniweb is education forum to help to members to learn and also help a certain extend. The way you describe it, it's more than just 1 file. The code you posted above is really #2.

About CURL here is a link about what I'm talking about this is for #3:

http://bavotasan.com/2011/post-url-using-curl-php/

There should be a file that has a similiar code to the one I post.

I didn't think you were being mean and I wasn't being sarcastic. Don't worry about it. I wouldn't be sarcastic to people on a board that I registered for free and people have tried to help me out on. I genuinely appreciatted both the advice you gave and the comment, from my perspective they were both truly useful. You may notice that I upvoted that post because I thought it was a good one.

I'm continuing to look into cURL, I haven't figured out how it helps yet because getimage.php always seems to return the correct image. The big code block above is capable of formatting the correct request (which would be passed to itself and then turned into an html image tag so the users browser calls get image). Uh... oh... I think I may have just solved one of my problems. The logic function doesn't need to know the day that was entered, just the number of the loop index!

Member Avatar for diafol

I'd suggest using a datepicker for this. Pasting your own calendar doesn't make much sense to me. If you're scraping sites for cartoons, ensure you have a right to do so. I couldn't see from where you're getting the images.

Hmm... a couple of people on this forum have recommended that I use jQuery. That's the datapicker plug-in that comes up. I'm not familiar with jQuery it looks like I should be so that's my next project I guess. Thanks for the advice about not linking images. Fortunately, the comic images on the website I linked to (http://www.frontandcover.com/comic/) are all my creation. The images are stored in a folder http://www.frontandcover.com/comic/daily/ , but it wouldn't make much sense to visit that file because for security the file permissions are set to 640. The getimage.php file referenced in my code is capable of reading those images and returning them so people can see them.

Member Avatar for LastMitch

@Goldfinch

I'm continuing to look into cURL, I haven't figured out how it helps yet because getimage.php always seems to return the correct image. The big code block above is capable of formatting the correct request (which would be passed to itself and then turned into an html image tag so the users browser calls get image). Uh... oh... I think I may have just solved one of my problems. The logic function doesn't need to know the day that was entered, just the number of the loop index!

It was very late last night. I was on Daniweb til 3am so I might have misread what you wrote and your intention too. I didn't notice the upvote either til now.

Here is what diafol mention about datepicker it looks exactly like your and it's in php:

http://www.triconsole.com/php/calendar_datepicker.php

Regarding about URL not changing images you can used this:

http://www.bin-co.com/php/scripts/misc/getlink/

commented: To Rectify what some retard did to LastMitch +0
Member Avatar for diafol

FYI: jQuery is easy. Here's some code to get the datepicker working. It'll work out of the box - so no need to change the urls:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>...</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
</head>
<body>

Date: <div id="datepicker"></div>

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script>
$(function(){
    $( "#datepicker" ).datepicker({
     onSelect: function(dateText, inst) {
        var date = $(this).val();
        alert(date);
    }
    });
});
</script>

</body>    
</html>

P.S. although a tight schedule kept me away from posting a proper response I wanted to thank you both for your help. I was able to implement it to get my script working.

Member Avatar for diafol

Great. Perhaps in order to help others, if you could post the code that finally got it to work?

Sure, the code required to achieve this only took a small modification to the jQuery and a little PHP.

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>...</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
</head>
<body>
<?php
date_default_timezone_set('EST');
    $date = $_GET['date'];
    if(strlen($date)<1){
    $date = substr(date(DATE_ATOM),0,10);
    $year=substr($date, 0, 4);
    $month=substr($date, 5,2);
    $day=substr($date, 8,2);
    } else {
    $year=substr($date, 6, 4);
    $month=substr($date, 0,2);
    $day=substr($date, 3,2);
    }
?>
<center><img src="getimage.php?date=<?php echo $year; echo "-"; echo $month; echo "-"; echo $day; ?>"></center>
<center>Choose the comic date you want to see:</center> <div id="datepicker" align="center"></div>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script language=javascript>
$(function(){
    $( "#datepicker" ).datepicker({
     onSelect: function(dateText, inst) {
        var date = $(this).val();
        window.location = "index.php?date="+date;
    }
    });
});
</script>
</body>    
</html>

I'm not sure its relevant, but for anyone who is also interested in how this interacts with the <img src="getimage.php?date=<?php echo $year; echo "-"; echo $month; echo "-"; echo $day; ?>"> code to retrieve an image, you can download the latest version of my script packaged for general use at http://www.frontandcover.com/software/dailycomic/

I could also retreive the code for the getimage.php file and post it here (the file hasn't changed since I posted this question), if asked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.