Jump to content
Sign in to follow this  
capcu

If statement

Recommended Posts

Hello,I'm really new to php. What I'm trying to do is if the two variables equal eachother than I only want to show one of the variables (StartDate). $event ->StartDate==$event ->EndDate ; Thanks for the help!

Share this post


Link to post
Share on other sites

The basic idea looks like this:

if ($event->StartDate == $event->EndDate){   // do something;}

I do not know what you mean by "show"

Edited by Deirdre's Dad

Share this post


Link to post
Share on other sites

what are you having trouble with? Are you familiar with conditional statements/logic?http://www.w3schools.com/php/php_if_else.asp

Share this post


Link to post
Share on other sites

Basically I don't want the date to show up twice so if the dates are both April 26 I only want to see ONE April 26 not April 26 April 26.

Share this post


Link to post
Share on other sites

That's the thing. I don't know what code you're using to "show" the dates, so I have no idea what to tell you. As a rule, people get better results here if they post the relevant code they are confused about. We probably don't need to see your whole script, just the part with the problem you need to solve.

Share this post


Link to post
Share on other sites

You could invert the conditon - always display the start date, and if the dates are NOT the same, display the end date as well, e.g.

//Do whatever you do to "show" the date e.g. "echo $event->StartDate;"if ($event->StartDate !== $event->EndDate) {//Do whatever you need to do to also "show" the end date, including outputting a separator, e.g. "echo '-', $event->EndDate;"}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×