Jump to content


Photo

$_GET Key


  • Please log in to reply
6 replies to this topic

#1 Baving

Baving
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 02 October 2006 - 04:44 PM

I am currently using this script: -

<? if ($_GET) {

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

?>

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.

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 October 2006 - 04:48 PM

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

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

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 02 October 2006 - 04:49 PM

each $_GET as array

$group = $_GET['group'];

echo $group;

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 02 October 2006 - 04:52 PM

Just as a notice... $_GET is always 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:
if(count($_GET)>0)


#5 Baving

Baving
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 02 October 2006 - 04:59 PM


<?php

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

good luck


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?



#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 02 October 2006 - 05:06 PM

Try this:
<?php
foreach($_GET as $key => $val)
{
	$keys[] = $key;
	$vals[] = "'{$val}'";
}

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


#7 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 October 2006 - 05:15 PM

or, just do it all at once in your query if that's what you're after:
<?php
$q = mysql_query("INSERT INTO table (" . implode(',', array_keys($_GET)) . ") VALUES ('" . implode("','", $_GET) . "')");
?>

don't forget to implode() with the quotes around all your values
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users