Solved

show region if

Posted on 2009-07-09
7
261 Views
Last Modified: 2012-05-07
How do I say. Only show region if $row_WAATKroi['printer'] equals 1 or 2?
0
Comment
Question by:petewinter
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:lharrispv
Comment Utility
if ($row_WAATKroi['printer'] ===1  || $row_WAATKroi['printer'] ===2)
//show region code here
;
0
 

Author Comment

by:petewinter
Comment Utility
Thanks for the reply, but it's not working. Can you please check my code:

<?php if ($row_WAATKroi['printer'] ===1  || $row_WAATKroi['printer'] ===2) { // Begin Show Region ?>
<li class="t3"><a href="#p7EPMc1_3" id="p7EPMtrg1_3">Rental</a></li>
<?php } // End Show Region ?>
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
Not sure why you are using the === construct, so if you do not know why you are testing for equivalence instead of equality, you probably want to use the == construct.

Have you printed out the $row_WAATKroi array with var_dump() to see what the values are for 'printer' in that array?
<?php 
 

if ($row_WAATKroi['printer'] ==1  || $row_WAATKroi['printer'] ==2) 

{ 

// Begin Show Region 

?>
 

<li class="t3"><a href="#p7EPMc1_3" id="p7EPMtrg1_3">Rental</a></li>
 

<?php 

} // End Show Region 

?>

	 

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Closing Comment

by:petewinter
Comment Utility
Perfect. Thanks Ray
0
 
LVL 8

Expert Comment

by:lharrispv
Comment Utility
try this..

<?php if ($row_WAATKroi['printer'] ==1  || $row_WAATKroi['printer'] ==2)
// Begin Show Region
echo  '<li class="t3"><a href="#p7EPMc1_3" id="p7EPMtrg1_3">Rental</a></li>';
// End Show Region
?>
notice I did two things.  1) rather than breaking out of php I used the echo to write the html to screen and 2 based on the if statement description at w3schools I took the curly brackets out (as was in my original example).

http://www.w3schools.com/php/php_if_else.asp

0
 
LVL 8

Expert Comment

by:lharrispv
Comment Utility
oh and the reason I had three equals (===) is because it makes a strick comparison...
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks for the points.  Almost without exception the form data contains character strings instead of numeric values.  So, for example, a numeric (integer) value 3 is not considered the same as a character string "3" if you use the === operator.  However due to PHP type juggling, the number and character string are considered the same if you use the == operator.

Best regards, ~Ray
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now