Baving Posted October 2, 2006 Share Posted October 2, 2006 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?permissionIt 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 printpermission&group=AThanks. Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/ Share on other sites More sharing options...
obsidian Posted October 2, 2006 Share Posted October 2, 2006 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 stringecho $_SERVER['QUERY_STRING'];// individual items:foreach ($_GET as $key => $val) { echo "{$key} => {$val}<br />\n";}?>[/code]good luck Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102469 Share on other sites More sharing options...
alpine Posted October 2, 2006 Share Posted October 2, 2006 each $_GET as array$group = $_GET['group'];echo $group; Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102470 Share on other sites More sharing options...
Daniel0 Posted October 2, 2006 Share Posted October 2, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102476 Share on other sites More sharing options...
Baving Posted October 2, 2006 Author Share Posted October 2, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102480 Share on other sites More sharing options...
Daniel0 Posted October 2, 2006 Share Posted October 2, 2006 Try this: [code]<?phpforeach($_GET as $key => $val){ $keys[] = $key; $vals[] = "'{$val}'";}$query = "INSERT INTO table (".join(',',$keys).") VALUES(".join(',',$vals.");";echo $query;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102481 Share on other sites More sharing options...
obsidian Posted October 2, 2006 Share Posted October 2, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.