473,385 Members | 1,919 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,385 software developers and data experts.

Matching GET values...

All,
I am trying to pass each GET variable to a function and check if it was
expected.
For example, here is a sample link:

index.php?name=modname&file=filename&func=1

the problem is, instead of returning:
match
match
match

it returns:

match
no match
no match
no match
match
no match
no match
no match
match

I know the problem is something with the =each, because it is evaluating
each item against each other, I just don't know how to fix it.

function bmcheck ($bmc, $g)
{
$bmchk = 0;
while (list ($key, $val) = each ($bmc)) {
if ($val == $g) {
echo "match";
echo "<br>";
} else {
echo "no match";
echo "<br>";
}
}
}

$bmc = array("name","file","func");
foreach ($_GET as $gvalue => $g) {
bmcheck($bmc, $gvalue);
}

Basically, when I'm done, if something like this was passed:
index.php?name=modname&file=filename&func=1&bad=no tsupposedtobehere
then I would see 3 "matches" and 1 "no match" for the "bad" parameter.

I hope this makes some sense =)
Thanks.
Jul 17 '05 #1
3 1310
Dimension7 wrote:
All,
I am trying to pass each GET variable to a function and check if it was
expected.
For example, here is a sample link:

index.php?name=modname&file=filename&func=1 (...) I know the problem is something with the =each, because it is evaluating
each item against each other, I just don't know how to fix it.

function bmcheck ($bmc, $g)
{
$bmchk = 0;
What's this $bmchk for ? You do not use at all!
Well ... I do :)
while (list ($key, $val) = each ($bmc)) {
if ($val == $g) { $bmchk = 1;
}

$bmchk was initialized to 0 before the while() and will only get set to
1 if at least one of the $bmc keys matches the $g parameter.

#> echo "match";
#> echo "<br>";
#> } else {
#> echo "no match";
#> echo "<br>";
#> } }
Now all keys have been checked and $bmchk is either 0 (no matches) or 1
(1 or more matches)

if ($bmchk) echo "match<br>";
else echo "no match<br>";
}

$bmc = array("name","file","func");
foreach ($_GET as $gvalue => $g) {
bmcheck($bmc, $gvalue);
}

Basically, when I'm done, if something like this was passed:
index.php?name=modname&file=filename&func=1&bad=no tsupposedtobehere
then I would see 3 "matches" and 1 "no match" for the "bad" parameter.

I hope this makes some sense =)


I hope my post makes sense :-)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
Dimension7 <di*******@seven.com> wrote:
$bmc = array("name","file","func");
foreach ($_GET as $gvalue => $g) {
bmcheck($bmc, $gvalue);
}

Basically, when I'm done, if something like this was passed:
index.php?name=modname&file=filename&func=1&bad=no tsupposedtobehere
then I would see 3 "matches" and 1 "no match" for the "bad" parameter.


With bmcheck you are trying to reinvent array_key_exists(), sounds kind
of silly to me :)

function bmcheck($arr,$key)
{
if(array_key_exists($key,$arr))
{
echo "match";
}
else
{
echo "nomatch";
}
}
--

Daniel Tryba

Jul 17 '05 #3
On 29 Apr 2004 08:37:27 GMT
Pedro Graca <he****@hotpop.com> wrote:
Dimension7 wrote:
All,
I am trying to pass each GET variable to a function and check if
it was expected.
For example, here is a sample link:

index.php?name=modname&file=filename&func=1 (...)
I know the problem is something with the =each, because it is
evaluating each item against each other, I just don't know how to
fix it.

function bmcheck ($bmc, $g)
{
$bmchk = 0;


What's this $bmchk for ? You do not use at all!
Well ... I do :)
while (list ($key, $val) = each ($bmc)) {
if ($val == $g) {

$bmchk = 1;


break;
}


You found what you're looking for, just stop then.
Jul 17 '05 #4

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

Similar topics

17
by: Andrew McLean | last post by:
I have a problem that is suspect isn't unusual and I'm looking to see if there is any code available to help. I've Googled without success. Basically, I have two databases containing lists of...
2
by: rowan[canspam] | last post by:
I have two tables ITEMS: items,description,mfg MANUFACTURER: mfg,full_name The items database has 230,000 records, the manufacturer, 493 records. I want to see how many records in the...
2
by: Gary Greenberg | last post by:
2
by: Hennie | last post by:
I apologise if this is a stupid question, but I would appreciated any help on this subject. I want to create a view (VIEW_1 in example below) where I take numeric values from a field in one...
2
by: vvyshak | last post by:
Hi all.. I have two tables such as cisco and ciscocom. and i wan to compare each row of ciscocom with cisco having same column values. i wan to get the count of matching columns for each row in...
9
by: Jim Lewis | last post by:
Anyone have experience with string pattern matching? I need a fast way to match variables to strings. Example: string - variables ============ abcaaab - xyz abca - xy eeabcac - vxw x...
16
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
6
by: andyalean1 | last post by:
Hello, I am trying to match an Id number that is shared across 2 xml files.I seem to be do the right thing bu it won`t display a match.Can you please help me find my error. I have a problem matching...
5
by: gentsquash | last post by:
In a setting where I can specify only a JS regular expression, but not the JS code that will use it, I seek a regexp component that matches a string of letters, ignoring case. E.g, for "cat" I'd...
2
by: lorlarz | last post by:
Looking for feedback on Matching Exercises Maker/ Builder: http://mynichecomputing.com/ReadIt/translateT.html For one thing, I am concerned about storing the matching kwork (known word) as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.