Jump to content

[SOLVED] $_GET[] help


dbx

Recommended Posts

the $_GET var is a super var in PHP. It is used to retrieve values from the URL

 

Example:

 

If your URL looks like this: www.yoursitehere.com/page.php?id=54

 

You would use $_GET like this

 

$id = $_GET['id'];

 

The $_GET global retrieves the value of id

Link to comment
https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658033
Share on other sites

I think what the OP is trying to do is extract data from a query string. However (as far as I know), you can only use $_GET when the data is passed directly through the URL, not as a string stored in a variable.

 

What you can do (which requires some work) is to use parse_url(). This function can be used to return the query-string portion of the url.

 

For example,

 

<?php
$myURL = "http://www.mysite.com/index.php?a=1&b=2";
echo parse_url($myURL, PHP_URL_QUERY);
// Returns: a=1&b=2
?>

 

In order to get the info that you want, you're going to have to use different function to break up the resulting string into parts (hint: explode()).

 

http://us2.php.net/manual/en/function.parse-url.php

 

Link to comment
https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658043
Share on other sites

change.php?SL-0009000_4080755_678.jpg=1&SL-0009000_6013157_16.jpg=2&SL-0009000_4354083_126.jpg=3&area=paf&ref=SL-0009000

 

if($result)
{
while($row = mysql_fetch_array($result)) {

$dbfile=$row["file"];

echo $dbfile."<br />";

$sentfile=$_GET[$dbfile];

echo "Sent file: ".$sentfile."<br />";

}
}

 

Displays:

 

SL-0009000_4080755_678.jpg

Sent file:

SL-0009000_6013157_16.jpg

Sent file:

SL-0009000_4354083_126.jpg

Sent file: 

Link to comment
https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658045
Share on other sites

So you want it to read

 

SL-0009000_4080755_678.jpg
Sent file: 1
SL-0009000_6013157_16.jpg
Sent file: 2
SL-0009000_4354083_126.jpg
Sent file: 3

 

? If my memory is right, dots are converted to underscores when used as the name in a query string. Why not swap the names and values, so the URL looks like

 

change.php?1=SL-0009000_4080755_678.jpg&2=SL-0009000_6013157_16.jpg&3=SL-0009000_4354083_126.jpg&area=paf&ref=SL-0009000

 

and then use

 

if($result)
{
while($row = mysql_fetch_array($result)) {

$dbfile=$row["file"];

echo $dbfile."<br />";

echo "Sent file: ".array_search($dbfile, $_GET)."<br />";

}
}

Link to comment
https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658048
Share on other sites

Archived

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

×
×
  • Create New...

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.