473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Get vars in URL

Hi all,

:)

I have an URL like this index.php?a=0&b=0&c=1&d=0&e=0&f=0

My prob now is: how can I find out if only *one* get var (a,b,d,d,e,f)
is 1?
I dopn't care about the other, i must detect, if *only one* var in the
url has its value 1, and all others are 0 then...

Thanks in advance - you are a great group here!

Marc
Jul 17 '05 #1
4 2017
Nel
"Marc Labtec" <ph*@komatia.com> wrote in message
news:ad**************************@posting.google.c om...
Hi all,

:)

I have an URL like this index.php?a=0&b=0&c=1&d=0&e=0&f=0

My prob now is: how can I find out if only *one* get var (a,b,d,d,e,f)
is 1?
I dopn't care about the other, i must detect, if *only one* var in the
url has its value 1, and all others are 0 then...

Thanks in advance - you are a great group here!

Marc

I am sure there are several ways to do this, but if you know that the values
will always be 1 or 0, you could simply add the values together.

if ($a+$b+$c+$d+$e+$f == 1) { OK } else { NOT OK }

Nel
Jul 17 '05 #2
On Fri, 11 Jun 2004 10:53:37 +0100, "Nel" <ne***@ne14.co.NOSPAMuk>
wrote:
"Marc Labtec" <ph*@komatia.com> wrote in message
news:ad**************************@posting.google. com...
Hi all,

:)

I have an URL like this index.php?a=0&b=0&c=1&d=0&e=0&f=0

My prob now is: how can I find out if only *one* get var (a,b,d,d,e,f)
is 1?
I dopn't care about the other, i must detect, if *only one* var in the
url has its value 1, and all others are 0 then...

Thanks in advance - you are a great group here!

Marc

I am sure there are several ways to do this, but if you know that the values
will always be 1 or 0, you could simply add the values together.

if ($a+$b+$c+$d+$e+$f == 1) { OK } else { NOT OK }


But as they're being passed by GET, none of the values can be
guaranteed.

Also, what about these scenarios:

index.php?a=-1&b=1&c=1&d=0&e=0&f=0

index.php?a=0&b=1&c=2&d=3&e=4&f=5

index.php?a=0&b=0&c=1&d=0&e=0&f=0&g=1&h=1&i=0

index.php?a=1

From the OP:
My prob now is: how can I find out if only *one* get var (a,b,d,d,e,f)
is 1?
I dopn't care about the other, i must detect, if *only one* var in the
url has its value 1, and all others are 0 then...


There is a contradiction here. He says "I don't care about the other",
but then says "if *only one* var in the url has its value 1, and all
others are 0 then..."

So, must the other GET variables be zero or not?

You could iterate through the $_GET[] array, making a count of the 1's
and 0's and then test those counts. The sum of the counts should equal
the number of GET variables.

--
David ( @priz.co.uk )
Jul 17 '05 #3
$result = ( count(array_keys($_GET,1)) == 1 ); // $result is true or false

ph*@komatia.com (Marc Labtec) wrote in message news:<ad**************************@posting.google. com>...
Hi all,

:)

I have an URL like this index.php?a=0&b=0&c=1&d=0&e=0&f=0

My prob now is: how can I find out if only *one* get var (a,b,d,d,e,f)
is 1?
I dopn't care about the other, i must detect, if *only one* var in the
url has its value 1, and all others are 0 then...

Thanks in advance - you are a great group here!

Marc

Jul 17 '05 #4
On 11 Jun 2004 02:06:12 -0700, ph*@komatia.com (Marc Labtec) wrote:
I have an URL like this index.php?a=0&b=0&c=1&d=0&e=0&f=0

My prob now is: how can I find out if only *one* get var (a,b,d,d,e,f)
is 1?
I dopn't care about the other, i must detect, if *only one* var in the
url has its value 1, and all others are 0 then...


Something like:

<?php
$matchVar = '';
$ok = false;
foreach (array('a','b','c','d','e','f') as $var)
if (@$_GET[$var] == 1)
if ($matchVar) // double match
$ok = false;
else { // found one
$matchVar = $var;
$ok = true;
}
elseif (@$_GET[$var] != 0) // bad value
$ok = false;

if ($ok)
print "Match found = $matchVar";
else
print "Some invalid combination";

?>

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: james | last post by:
I am new to php and need some help getting the session variables into include files. (after-thought, Sorry for the drawn out post but I really, really need help....;) Here's what I'm doing.. ...
2
by: Claire | last post by:
hi, i use vars() or dir() to get variables. I use them in a def block, so i get variables of that block. How can i get variables from the namespace __main__ ? I use python in interactive mode and...
6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
3
by: Jon | last post by:
I have a couple of tables I want to load into a dataset and keep around pretty much forever, although they will need to be refreshed every so often. I can either put the dataset into an...
3
by: freak | last post by:
Using PHP version: 4.3.7 I try to define my db vars outside the class! Why this will not work? class mytest{ //***************** set db settings *************************** var $HOST ; var...
10
by: John A Grandy | last post by:
Say I have Class1 which contains static Class2 var1 = new Class2(); Is Class2 constructor code only executed if var1 is referenced in the code-execution path ? Or is Class2 constructor code...
2
by: Jeff | last post by:
....still new to .net 2005 using VB. Do I understand correctly that the value of a session variable is actually stored in the server's ram, but relies on the asp.net session ID cookie that...
19
RMWChaos
by: RMWChaos | last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to...
6
by: goodguyjam | last post by:
Hi all, I'm having trouble with mysql. I've just finished my php coding for HTTP authentication and with some help am now getting a login window pop up whenever I click on a link on my website...
5
by: Ross | last post by:
Forgive my newbieness - I want to refer to some variables and indirectly alter them. Not sure if this is as easy in Python as it is in C. Say I have three vars: oats, corn, barley I add them...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.