Jump to content

Archived

This topic is now archived and is closed to further replies.

Baving

$_GET Key

Recommended Posts

I am currently using this script: -

[code]<? if ($_GET) {

$mode = key($_GET);
print $mode;
}

?>[/code]

Which is grabbing the text on the $_GET. But this is only collecting the first bit of information e.g.:-

index.php?permission

It would only print permission.

Is there anyway so that it will get more information from the $_GET statment? e.g.

index.php?permission&group=A

So it would print

permission&group=A

Thanks.

Share this post


Link to post
Share on other sites
well there are many ways to access parts of a query string like that. try these out and see what you get:
[code]
<?php
// entire query string
echo $_SERVER['QUERY_STRING'];

// individual items:
foreach ($_GET as $key => $val) {
  echo "{$key} => {$val}<br />\n";
}
?>
[/code]

good luck

Share this post


Link to post
Share on other sites
each $_GET as array

$group = $_GET['group'];

echo $group;

Share this post


Link to post
Share on other sites
Just as a notice... $_GET is [i]always[/i] true as it by default is array(), so if($_GET) would be unnecessary. To do what I think you're trying to accomplish you should use this: [code]if(count($_GET)>0)[/code]

Share this post


Link to post
Share on other sites
[quote author=obsidian link=topic=110257.msg445375#msg445375 date=1159807699]

[code]
<?php

// individual items:
foreach ($_GET as $key => $val) {
  echo "{$key} => {$val}<br />\n";
}
?>
[/code]

good luck
[/quote]

That is what I am needing :)

Any ideas how I could return the array to insert it into a database?

So..

$query = mysql_query("INSERT INTO whatever (list) VALUES('$input')");

With $input being the contents of the foreach array?

Share this post


Link to post
Share on other sites
Try this: [code]<?php
foreach($_GET as $key => $val)
{
$keys[] = $key;
$vals[] = "'{$val}'";
}

$query = "INSERT INTO table (".join(',',$keys).") VALUES(".join(',',$vals.");";
echo $query;
?>[/code]

Share this post


Link to post
Share on other sites
or, just do it all at once in your query if that's what you're after:
[code]
<?php
$q = mysql_query("INSERT INTO table (" . implode(',', array_keys($_GET)) . ") VALUES ('" . implode("','", $_GET) . "')");
?>
[/code]

don't forget to implode() with the quotes around all your values

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.