If statement trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stroodle
Forum Newbie
Posts: 3
Joined: Tue Feb 08, 2011 8:16 am

If statement trouble

Post by Stroodle »

Hey guys,

I'm a web designer without any experience with PHP or any kind of coding really. My company has a website in PHP and we need something changed. Basically when you view 2 of our product lines we need a different header to appear. I did my best before having to come here but I got stuck. Below is the code i added in and below that is what we normally have. When "crown" or "monarch" is viewed, I need seriesHeader2 to be displayed. I apologize about the outdated code. This page is soon being re-designed. Thanks in advance

Code: Select all

if (strtolower($series) == "crown" "monarch")
 echo "<div class='seriesHeader2' />"

else

Code: Select all

echo "<div class='seriesHeader' /><table width='440' border='0' ><tr><td width='50' align=right valign=top class='seriesHeadTitle'>".strtoupper($seriesName)."<br /><span style='font-size:9pt;font-style:italic;'>series</span></td><td class='seriesHeadMain'>".$seriesInfo."</td></tr></table></div>";
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: If statement trouble

Post by Reviresco »

1. You need to add braces to the if-else statement like so:

Code: Select all

if ($something == 'something') {
	//do stuff here
}
else {
	//do different stuff here
}
2. For the if statement, you need to add the "or" operator: ||

Code: Select all

if (strtolower($series) == "crown" || strtolower($series) =="monarch") {
Mince
Forum Commoner
Posts: 25
Joined: Mon Aug 03, 2009 9:36 am

Re: If statement trouble

Post by Mince »

Stroodle wrote:

Code: Select all

if (strtolower($series) == "crown" "monarch")
 echo "<div class='seriesHeader2' />"

else
You can leave the strtolower function, as it's unnecessary here. What you need is something like this:

Code: Select all

if($series == "crown" or $series == "monarch")
{
      $series_class = "seriesHeader2";
}
else
{
     $series_class = "seriesHeader";
}
echo "<div class='{$series_class}' /><table width='440' border='0' ><tr><td width='50' align=right valign=top class='seriesHeadTitle'>".strtoupper($seriesName)."<br /><span style='font-size:9pt;font-style:italic;'>series</span></td><td class='seriesHeadMain'>".$seriesInfo."</td></tr></table></div>";
Stroodle
Forum Newbie
Posts: 3
Joined: Tue Feb 08, 2011 8:16 am

Re: If statement trouble

Post by Stroodle »

Since I'm in over my head, I'll have to stick with one reply at a time.

@Reviresco. So something like this? It says there's an error on the first line. Maybe I'm missing something

Code: Select all

if (strtolower($series) == "crown" || strtolower($series) =="monarch")

{ echo "<div class='seriesHeader2' />" }
else {
echo "<div class='seriesHeader' /> 
<table width='440' border='0' ><tr><td width='50' align=right valign=top class='seriesHeadTitle'>".strtoupper($seriesName)."<br /><span style='font-size:9pt;font-style:italic;'>series</span></td><td class='seriesHeadMain'>".$seriesInfo."</td></tr></table></div>"; }
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: If statement trouble

Post by AbraCadaver »

You're missing a ; at the end of one of your lines.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Stroodle
Forum Newbie
Posts: 3
Joined: Tue Feb 08, 2011 8:16 am

Re: If statement trouble

Post by Stroodle »

Thanks a lot guys. It's working perfectly. I had to add in the ; as well as the following to last echo

Code: Select all

<table width='440' border='0' ><tr><td width='50' align=right valign=top class='seriesHeadTitle'>".strtoupper($seriesName)."<br /><span style='font-size:9pt;font-style:italic;'>series</span></td><td class='seriesHeadMain'>".$seriesInfo."</td></tr></table></div>
Thanks again. You rock!
Post Reply