dbx Posted October 6, 2008 Share Posted October 6, 2008 Hi, I'm a little stuck on the following: $name="filename";//value would be taken from DB $val1=$_GET[$name]; //How do I use $name in there? Thanks. Link to comment https://forums.phpfreaks.com/topic/127224-solved-_get-help/ Share on other sites More sharing options...
dennismonsewicz Posted October 6, 2008 Share Posted October 6, 2008 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 More sharing options...
thebadbad Posted October 6, 2008 Share Posted October 6, 2008 Your code is setting $val1 to what $_GET['filename'] is containing. If that's what you want, you're doing it right. Link to comment https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658036 Share on other sites More sharing options...
dbx Posted October 6, 2008 Author Share Posted October 6, 2008 That is what I want it to do. Something else must be wrong... Thanks for your replies! Link to comment https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658037 Share on other sites More sharing options...
dennismonsewicz Posted October 6, 2008 Share Posted October 6, 2008 can you post more of your code Link to comment https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658038 Share on other sites More sharing options...
ibechane Posted October 6, 2008 Share Posted October 6, 2008 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 More sharing options...
dbx Posted October 6, 2008 Author Share Posted October 6, 2008 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 More sharing options...
thebadbad Posted October 6, 2008 Share Posted October 6, 2008 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 More sharing options...
dbx Posted October 6, 2008 Author Share Posted October 6, 2008 It works! I used str_replace to remove ".jpg" from this and the previous page, and now they match. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658055 Share on other sites More sharing options...
thebadbad Posted October 6, 2008 Share Posted October 6, 2008 Good. Guess it indeed was the dot causing the problem then. Link to comment https://forums.phpfreaks.com/topic/127224-solved-_get-help/#findComment-658057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.