SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: php question

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php question

    Hi Gang,
    Is there a way to insert PHP script in a HTML calander document to automatically highlight the date for "todays date". If there is can someone give me an example. In other words today's date is March 15. Can I utilize a PHP script within my HTML file to highlight March 15? Can the script automatically highlight March 16 tomorrow and every day threrafter? Obviously I'm new to PHP. I know there are PHP calender examples out there, but they are too complicated for me to understand right now. For the time being I would like to modify my HTML calender (If I can) until I become more PHP literate.

    Thanks a bunch,

    DAD

  2. #2
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do this - can you please post some example code from your HTML calender so I can see what we are dealing with.

    Regards

    Guy

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ok, here is the code for the calender

    <TABLE BORDER=3 CELLSPACING=3 CELLPADDING=3>
    <TR>
    <TD COLSPAN="7" ALIGN=center><B>December 2001</B></TD>
    </TR>

    <TR>
    <TD COLSPAN="7" ALIGN=center><I>Another year comes to an end</I></TD>
    </TR>

    <TR>
    <TD ALIGN=center>Sun</TD>
    <TD ALIGN=center>Mon</TD>
    <TD ALIGN=center>Tue</TD>
    <TD ALIGN=center>Wed</TD>
    <TD ALIGN=center>Thu</TD>
    <TD ALIGN=center>Fri</TD>
    <TD ALIGN=center>Sat</TD>
    </TR>

    <TR>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center>1</TD>
    </TR>

    <TR>
    <TD ALIGN=center>2</TD>
    <TD ALIGN=center>3</TD>
    <TD ALIGN=center>4</TD>
    <TD ALIGN=center>5</TD>
    <TD ALIGN=center>6</TD>
    <TD ALIGN=center>7</TD>
    <TD ALIGN=center>8</TD>
    </TR>

    <TR>
    <TD ALIGN=center>9</TD>
    <TD ALIGN=center>10</TD>
    <TD ALIGN=center>11</TD>
    <TD ALIGN=center>12</TD>
    <TD ALIGN=center>13</TD>
    <TD ALIGN=center>14</TD>
    <TD ALIGN=center>15</TD>
    </TR>

    <TR>
    <TD ALIGN=center>16</TD>
    <TD ALIGN=center>17</TD>
    <TD ALIGN=center>18</TD>
    <TD ALIGN=center>19</TD>
    <TD ALIGN=center>20</TD>
    <TD ALIGN=center>21</TD>
    <TD ALIGN=center>22</TD>
    </TR>

    <TR>
    <TD ALIGN=center>23</TD>
    <TD ALIGN=center>24</TD>
    <TD ALIGN=center>25</TD>
    <TD ALIGN=center>26</TD>
    <TD ALIGN=center>27</TD>
    <TD ALIGN=center>28</TD>
    <TD ALIGN=center>29</TD>
    </TR>

    <TR>
    <TD ALIGN=center>30</TD>
    <TD ALIGN=center>31</TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>

    </TR>

    </TABLE>

  4. #4
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would very much suggest starting from scratch and writing a calender in PHP, it should not be too difficult:

    Here is an example based on your current html calender:

    calender.php
    PHP Code:

    <TABLE BORDER=3 CELLSPACING=3 CELLPADDING=3>
    <TR>
    <TD COLSPAN="7" ALIGN=center><B><?php echo date('F Y'); ?></B></TD>
    </TR>

    <TR>
    <TD COLSPAN="7" ALIGN=center><I>Another year comes to an end</I></TD>
    </TR>

    <TR>
    <TD ALIGN=center>Sun</TD>
    <TD ALIGN=center>Mon</TD>
    <TD ALIGN=center>Tue</TD>

    <TD ALIGN=center>Wed</TD>
    <TD ALIGN=center>Thu</TD>
    <TD ALIGN=center>Fri</TD>
    <TD ALIGN=center>Sat</TD>
    </TR>

    <TR>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    <TD ALIGN=center></TD>
    </TR>
    <TR>
    <?php
    for($i=1;$i<32;$i++) {

    $weekstarts = array(1,5,12,19,26); // Week starts in March

    for($c=0;$c<5;$c++) {

    if(
    $i == $weekstarts[$c]) {
    echo 
    '</TR><TR>';
    }

    }


    if(
    date('j') == $i) {
    // Make day bold
    echo '<TD ALIGN=center><b>'.$i.'</b></TD>';
    } else {
    // Normal
    echo '<TD ALIGN=center>'.$i.'</TD>';
    }


    }
    ?>


    </TR>

    </TABLE>
    I have not tested the above example and it is not perfect, but it might give you an idea as to what to do.

    Have a look at the date function for more info on date handling.

    What I have done in the above example is loop through each day, check to see if it is the end of the week, if so then do a </TR><TR> and then check to see if the day is today and make it bold.

    Good Luck

    Guy

    Regards

    Guy
    Last edited by mrwooster; Mar 15, 2007 at 12:40. Reason: Update script

  5. #5
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have now edited the above code to work correctly, as you can see though it still needs work, for example the 1st, 30th and 31st are in the wrong places - but I hope that the above will be able to help you build a calender in PHP.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks Rooster

    Any help is appereciated!

  7. #7
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hate to be picky but you really gotta look into writing xhtml valid code - save yourself, or someone else alot of pain now by getting up to speed and jumping into dreamweaver, file > convert > xhtml strict... if you don't have dreamweaver its probably not going to be so much fun to do...

    sorry I dont have any input regarding calenders, in fact looking forward to some more replies because i'm about to face a similar problem myself
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •