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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted October 6, 2008 Share Posted October 6, 2008 can you post more of your code Quote Link to comment 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 Quote Link to comment 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: Quote Link to comment 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 />"; } } Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment 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.