if statement matches multiple values
Page 1 of 111 Replies - 86007 Views - Last Post: 01 April 2008 - 08:14 PM
#1
if statement matches multiple values
Posted 27 June 2006 - 08:29 AM
checks to see if a $locationid is equal to one of the following numbers. (dont have the numbers yet, but it only has to equal one, and then execute the action, not all of them)
then i need a command to tell the webpage to go to another page if that requirement is met.
can you do
if ($locationid == "152,234,598");
152 , 234, 598 all being seperate numbers.
the numbers will be the same forever, or at least not changed very often at all, so yeah. thanks for the help
Replies To: if statement matches multiple values
#2
Re: if statement matches multiple values
Posted 27 June 2006 - 08:37 AM
if ($locationid == 152 || $locationid==234 || $locationid==598)
if statements do not take a semi colon as terminator
the syntax will change somewhat if the numbers are actually of the string type.
#3
Re: if statement matches multiple values
Posted 27 June 2006 - 08:50 AM
if ($foo == 1337 && $var == "superduper")
This post has been edited by max302: 27 June 2006 - 08:51 AM
#4
Re: if statement matches multiple values
Posted 27 June 2006 - 09:16 AM
Quote
The styles are the same, but you definatly want OR in this case.
If at any time you are looking for an identity equality (not just a number equality) use ===
#5
Re: if statement matches multiple values
Posted 27 June 2006 - 09:35 AM
just for simplicitys sake
lets say i define two variables
<?php $note = "HEllO WORLD. NOTE ONE"; ?>
<?php $note2 = "Note 2"; ?>
//later on.....
<?php
if ($id == 152 || $id==234 || $id==598)
echo "$note2";
} else {
echo "$note";
}
?>
now, the id number is coming from the fact the site name is
www1.airimba.com/tlee/test3.php?id=
now,
all i get when i do this is a blank page
This post has been edited by capty99: 27 June 2006 - 09:37 AM
#6
Re: if statement matches multiple values
Posted 27 June 2006 - 10:02 AM
$id=$_GET['id'];
It may also be the fact that the if statement has a closing brace, but know opening brace. Or it could be that the variable $id is interpreting it's value as a string, not a number.
#7
Re: if statement matches multiple values
Posted 27 June 2006 - 10:24 AM
thanks to all you helped.
i am very pleased.
#8
Re: if statement matches multiple values
Posted 27 June 2006 - 11:07 AM
just for my own sake,
because instead of a couple values as i had imagined, it turned out to be about 35, which i inputted just like that.
but would there have been an easier way to do that?
#9
Re: if statement matches multiple values
Posted 27 June 2006 - 11:25 AM
Something like this.
$someValue = "My brain melts at the thought.";
$arr = array(1,2,3,4,5,6,7,8,9,0);
if(in_array($someValue, $arr)) {
echo "I'm smart!";
} else {
echo "I liek milk!";
}
#10
Re: if statement matches multiple values
Posted 27 June 2006 - 11:27 AM
<?php $note = "HEllO WORLD. NOTE ONE"; ?>
<?php $note2 = "Note 2"; ?>
//later on.....
<?php
$id = var1;
switch($id)
{
case 152:
echo $note;
break;
case 234:
echo $note;
break;
case 598:
echo $note;
break;
default:
echo $note2;
break;
}
?>
i dunno exactly how you are going to have it all layed out, but the way i just posted would let you echo a different thing with each number that you returned. I'm sure you could do an || (or) to condense the code if you were going to have more than one number echo the same thing.
the default setting is what would be echoed if none of the other cases are true.. so if some number other than 152, 234, or 598 was returned it would display $note2
edit:added code tag
This post has been edited by the_hangman: 27 June 2006 - 11:28 AM
#11
Re: if statement matches multiple values
Posted 17 October 2006 - 01:16 PM
better this way
<?php $note = "HEllO WORLD. NOTE ONE"; ?>
<?php $note2 = "Note 2"; ?>
<?php
$id = var1;
switch($id)
{
case 152:
case 234:
case 598:
echo $note;
break;
default:
echo $note2;
break;
}
?>
regards :)
#12
Re: if statement matches multiple values
Posted 01 April 2008 - 08:14 PM
Amadeus, on 27 Jun, 2006 - 10:02 AM, said:
$id=$_GET['id'];
It may also be the fact that the if statement has a closing brace, but know opening brace. Or it could be that the variable $id is interpreting it's value as a string, not a number.
Hello everyone,
I was very pleased to see someone had the same problem as me and got it sorted! I was wondering if I could have some help with my coding....
I have a website that has a rank structure for members and the $rank is set in the global document.
I have done the same regarding the coding and also end up with a blank page. I see you say to set the $id=$_GET['id']; for this guys particular problem. So how do I set up a $id=$_GET['id']; and what does this actually mean and do?
So far all I can do to allow/refuse access to a page is use a $rank_check command at the top of the document. However, using this I can only seem to set one rank level with $rank_check == 5; for example or allow ranks above a certain level with $rank_check >=5;.
I would like to be able to specify which exact ranks I want to have access to the page content and have this so far:
<?php
$interactive = 1;
$page_title = "Council Offices Meeting Room";
$rank_check = 3;
include "../header.inc.php";
$game=$_GET['game'];
print "$openHTML";
if ($rank == 10 || $rank == 30 || $rank == 57 || $rank == 59 || $rank == 95 || $rank ==96 ||$rank ==97 || $rank ==98 || $rank ==99)
{
print "$content";
}
else
{
print "<center><p><p><br><br><p><font size=3>Sorry But you do not have access to the City Council Meeting Room. <br>This is a restricted area! Please click <a href=$base_url/city_offices/reception.php>here</a> to go back to the council offices";
}
$content .= " PAGE CONTENT HERE ";
print "$closeHTML";
?>
But as explained... all I get is a blank screen with the header working.
The log in page is where all the cookies and sessions are done so do I need to build a new session? Sorry but I am quite new to PHP so am a little vague and only know bits and pieces.
Would appreciate any help.
Thanks
Justin
|
|

New Topic/Question
Reply




MultiQuote





|