0

So I'm new to PHP and write bad code. I am trying to format a calendar to show the entries as list entries. Furthermore, if an event time was entered at 12 AM, I am trying to hide that outputted value. Here is the tutorial that I am using https://spunmonkey.com/display-contents-google-calendar-php/.

Here is the code that is from the tutorial:

     $eventdate = new DateTime($eventDateStr,$timezone);
     $newmonth = $eventdate->format("M");
     $newday = $eventdate->format("j");
     $newtime = $eventdate->format("g");
     $newtimeAM = $eventdate->format("A");

Here is what I am trying to do and my horribly written code (this if for the newtime div:

    <?php
         if ( $newtime="12" && $newtimeAM="AM") {
                echo $eventdate->format("");
            }  else {
                echo $newtime;


            }
        ?>  

I have written the same if statement for $newtimeAM. My questions are:

  1. Can I use the if statement to set the value to the outputted string, (like $newtime="12")?
  2. Can I use the format parameter to return an empty string, as to hide the values if the conditions are met?

Right now, it does display the calendar entry, but not with the time. For example, there is an entry that starts at 2 PM that I want the calendar to show, but it's not showing. Also, what references that anyone give to learn PHP online? I know w3 is pretty awesome and well as php.net.

Gabriel
  • 27
  • 4
  • `if ( $newtime="12" && $newtimeAM="AM")` you realize what this does right? It "assigns" instead of "comparing". So what you have now, will "always" be that, instead of comparing those two values. – Funk Forty Niner Jun 27 '17 at 13:38
  • Yeah that was dumb of me, and thanks for marking this as duplicate to a better question and answer! I can reference that now so much appreciated! – Gabriel Jun 27 '17 at 14:04

1 Answers1

0

Try fixing your if statement. One = assigns, two == checks!

if ( $newtime == "12" && $newtimeAM == "AM") {

The way your code is, you SET these vars, so nothing will output each time!

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39