05rmerce Posted January 14, 2008 Share Posted January 14, 2008 Hi, Please stay with me as I am finding this quite difficult to explain I would like to make a script that gets information from the database and echoes it to the page. That I can do. But more importantly I would like to have one file that is able to choose a different piece of information based on the URL. For example, in this post window: http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 Index.php can show the index, or with the bit on the end generates the post form. I would like to know how to add/use the ?action=post;board=1.0 Bit in my own scripts. I hope that has come across well. Thanks in advance 05rmerce Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/ Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 Use $_GET to grab that info after the ? Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439115 Share on other sites More sharing options...
toplay Posted January 14, 2008 Share Posted January 14, 2008 If you have PHP5 it's easy to build with: http://us.php.net/manual/en/function.http-build-query.php Like revraz stated, use $_GET ad in $_GET['action']. See $_GET info: http://us.php.net/manual/en/reserved.variables.php#reserved.variables.get FYI: http://us.php.net/manual/en/function.parse-url.php Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439123 Share on other sites More sharing options...
05rmerce Posted January 14, 2008 Author Share Posted January 14, 2008 Hi, Thanks very much, you were both very helpful I think the parse_url will help me perfectly, thanks again. Does SMF have any kind of reputation system that I can add too Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439132 Share on other sites More sharing options...
05rmerce Posted January 14, 2008 Author Share Posted January 14, 2008 Actually (and apologies for the double post). I have just realised that I have no idea on how to get the URL of the script that the user has entered? I feel stupid now Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439145 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 Lets say this is the URL http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 Now on index.php you have a $_GET['action'] that has "post" in it. Is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439151 Share on other sites More sharing options...
05rmerce Posted January 14, 2008 Author Share Posted January 14, 2008 Not exactly I would like a page to display different things based on what is after the .php? For example: http://server.com/index.php //Would load the main index from the database http://server.com/index.php?view=002 //Would execute different script to load the information for record 002. I think I can work it out myself, if you could be kind enough to demonstrate how I could set what the user has typed in (The URL) as a variable. Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439155 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 So it is what you mean, but you just don't realize it. http://server.com/index.php?view=2 <?php if ($_GET['view'] == 2) { echo "you picked 2"; } else { echo "something other than 2 was picked or nothing was"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439169 Share on other sites More sharing options...
toplay Posted January 14, 2008 Share Posted January 14, 2008 Read up on the $_GET info. In your second example the PHP variable $_GET['view'] would contain your value of 002 (or possibly just 2). If you want to assign it to another variable, simply do: $view = $_GET['view']; However, it's good coding practice to make sure the index "view" is there first. So, something like this is better: $view = isset($_GET['view']) ? $_GET['view'] : ''; Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439170 Share on other sites More sharing options...
05rmerce Posted January 14, 2008 Author Share Posted January 14, 2008 Looks perfect to me, will try and report back Quote Link to comment https://forums.phpfreaks.com/topic/85989-solved-little-help-with-php/#findComment-439171 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.