LB1234
asked on
What is the best way to write this short and simple PHP/HTML code?
If the if statement is true, I want the HTML below displayed, but there's gotta be a better than echoing out each line of HTML, right?
As always, thanks!
<?php
if (!isset($_GET["id"])) {
// then display this HTML below
<div id="menu">
<ul>
<li><a href="#">Pending Expenses</a></li>
<li><a href="#">Open Report</a></li>
</ul>
</div>
}
?>
As always, thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Logu, that doesn't make sense why that would work! Can you please explain the logic?
ASKER
Ray, ok so something like this?
<?php
if (!isset($_GET["id"])) {
// then display this HTML below
echo <<< EOT
<div id="menu">
<ul>
<li><a href="#">Pending Expenses</a></li>
<li><a href="#">Open Report</a></li>
</ul>
</div>
EOT;
}
?>
The learning resources in this article will help you get a handle on this, and many other PHP-related questions.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
something like this?Yes, but you'll find that the code is easier to maintain if you create your variables separately, away from the presentation (echo). That's why I assigned a variable to the HEREDOC string then echo the variable, instead of echo the HEREDOC
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris, but isn't anything not in PHP blocks automatically displayed? That's what's throwing me off here.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On the other hand, when you fix and maintain other people's code, you can get pretty good at reading code like Ray's last example where everything is all inter-mixed.
Dave :-)
I make most of my money doing that, Ray. Very educational and profitable.
Yeah, I had a similar experience last year. When I see a code smell, I go hourly immediately!
hourly? Is there another way???
Actually, I will do new jobs or small projects on a fixed quote when I know how it's going to go. I'm very good at the things I've already done 100 times...
Actually, I will do new jobs or small projects on a fixed quote when I know how it's going to go. I'm very good at the things I've already done 100 times...
Yeah me too. It takes about 100 times to get proficiency at my age ;-)
But Ray!! You're Still a Young Man....
Erm :-)
Open in new window