Forum Moderators: coopster

Message Too Old, No Replies

question about $_GET

         

supermanjnk

4:52 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Is it possible if i have a link like

widgets.com/index.php?article=1

i know how to get 1

echo $_GET['article'];

is there anyway to get article?
I am trying to make my page dynamic, but I need a way to get article.

for instance I'm using the following script for part of my site.

while ($fetch = mysql_fetch_object($urls)){
$linkage2 = $fetch->link;
if (isset($_GET[$linkage2])){
${$linkage2} = $_GET[$linkage2];
}
}

now i need some way to figure out what the ${$linkage2} variable is. so I can use it elseware, the problem is since it's dynamic it will never be the same thing so I can't just do one of my known gets, like $widgets

grandpa

5:06 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This will allow you to get the key, article. The $_GET variable is an associative array just like the $_POST variable.

foreach ($_GET as $key => $val)
{
echo "<br>$key $val";
}

article 1

supermanjnk

6:11 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



I thought i had tried that, but it wasn't working...

now it is, thanks.

kamkaz

8:15 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Useing the same idea I would use $POST. It is more private... but it all depends on your application.

supermanjnk

7:24 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



just a quick question, using
foreach ($_GET as $key => $val)
{
echo "<br>$key $val";
}

if I don't do it inside the loop $key is always equal to my last $_GET

which makes sense. However when I have a link that looks like this

index.php?page=1&topic=3&subsection=2

$key is always subsection and $val is always 2.

I've tried using a loop like this

for($i = 1; $i<=10; $i++){
foreach ($_GET as ${"key" . $i} => $val) {
}
echo "${"key" . $i}<br>";
}

which obviously doesn't work because for 1 it does the loop, then for 2 it does the loop, so everything still ends up being page. this is driving me nuts...
I need to get it so this is true below
$key1 = "page";
$key2 = "topic";
$key3 = "subsection";

any help would be great

grandpa

10:17 pm on Mar 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What do you have in $linkage2? It looks like you are only passing subsection, and not page or topic.

$linkage2 = $fetch->link;

I'll go a little further out on this limb.. have a look at the $fetch class and determine if you are returning the values for page and topic.

supermanjnk

10:37 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



linkage two is equal to whatever the link section of the database has in it.