justAnoob Posted January 3, 2010 Share Posted January 3, 2010 Can $_GET be used twice within one page? Meaning two different variables to be passed through the URL at the same time? Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 If you have multiple values in your URL string you can get them all.. $_GET has a limit to how many bytes it can hold but something like this. index.php?var1=tetst&var2=sdfsdf&var3=wfgdfgdfg can be access like this $var1 = $_GET['var1']; $var2 = $_GET['var2']; etc... Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 3, 2010 Share Posted January 3, 2010 Of course, Take into account you enter this url: www.example.com/index.php?page=1&style=blue In PHP, you can find them using: if (isset($_GET['page'])) { echo 'Page ID is set!, ID = ' . $_GET['page']; } else { echo 'Please enter an ID'; } if ($_GET['style'] == 'blue) { echo '<div style="background-color:blue;"> A div! </div>'; }' It's recommended to use isset() to find out if they're entered or not, or else it may return an error if you ask for it and it's not there. http://www.php.net/manual/en/reserved.variables.get.php Also, make sure you sanitize anything being outputted via GET variables. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Share Posted January 3, 2010 you can use the $_GET to get different values from the url, I am not sure about sending. I believe it is possible since The Global variable $_GET only gets in charge of making the variable value available though out the whole script what you call is the variable with different name not the super Global $_GET. you call the variables values through the $_GET Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 3, 2010 Share Posted January 3, 2010 you can use the $_GET to get different values from the url, I am not sure about sending. I believe it is possible since The Global variable $_GET only gets in charge of making the variable value available though out the whole script what you call is the variable with different name not the super Global $_GET. you call the variables values through the $_GET You can of course assign one: //index.php?arg=test $_GET['arg'] = "Foobar"; $arg = $_GET['arg']; // Will echo"FooBar" GET arguments are useful when the user needs to return to a specific setting on a page, such as ID number. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 Ok, The reason I ask is cause the page that loads has a URL like the following http://www.mysite.com/category.php?selecting=Video Games Video Games can differ depending on what category they choose on the previous page. Then, there is a pagination script with page numbers. $targetpage = "mypage.php"; <a href='$targetpage?page=1' So I would have to edit my $targetpage var ? Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Share Posted January 3, 2010 right now I have the same exact problem awww. where do you have your pagination script? in category.php Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 yeh Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 3, 2010 Share Posted January 3, 2010 I'm not 100% sure what you're meaning to do, are you wishing to use the pagination script with category.php? Then yes, you will need to change 'mypage.php' to 'category.php' Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Share Posted January 3, 2010 and what is the issues you have with $_GET and the pagination? is there some parameters that are not passing as you paginate? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 I get an error on this line $page = mysql_escape_string($_GET['page']); when my url reads like this already http://www.mysite.com/category.php?selecting=Video Games This is hard to explain Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 an undefined index error Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 3, 2010 Share Posted January 3, 2010 I get an error on this line $page = mysql_escape_string($_GET['page']); when my url reads like this already http://www.mysite.com/category.php?selecting=Video Games This is hard to explain If you're wanting to get 'Video Games', than use this: $page = htmlspecialchars($_GET['selecting']); Note escaping data does not sanitize it, only for SQL queries. HTMLspecialchars prevents any input that is not wanted (XSS forgery etc.). Remember, $_GET['whatever'] is url.php?whatever=foobar. If it doesn't exist, the GET statement will throw that error. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 Sorry for the confusion, let me try to explain again Page 1: has a list of categories when user clicks on one of the categories, they are taken to a new page, which would look like this http://www.mysite.com/category.php?selecting=Video Games The above URL would be called page 2 Page 2: when page 2 is diplayed, there may be 500 video games to be listed which brings in my pagination. my pagination script is having probs working with my url from above because there is alreay a variable in it. Here is some of my pag script $targetpage = "category.php"; $page = mysql_escape_string($_GET['page']); <a href='$targetpage?page= Of course the page= could be a number of variables within my pagination script. I'm not sure but it almost seems like my $targetpage var should be someting like category.php?selecting=video games ..... this way my pagination script variables come after the complete url of whatever category was chosen. Does any get this? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 this is kinda what I'm looking for on my pagination page http://www.tradekrazy.com/category_select_test0167.php?selecting=Video Games?page=1 Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Share Posted January 3, 2010 in page one do you have more than one field that users will have the option before the go to page2? I mean if it is a form with various fields? or is just one field like Video Game name: Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 3, 2010 Share Posted January 3, 2010 $targetpage = "category.php"; $page = htmlspecialchars($_GET['page']); <a href="$targetpage?selecting=".$_GET['selecting']."&page=$page"> Do you mean that? It'll retain the 'selecting' variable and ADD the page variable at the end, as the pagination script asks.. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Share Posted January 3, 2010 that will work like a charm! Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 There is more than one option,, it could be video games, old attic toys, christmas decorations, etc.... So yeh, that variable will always be different. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 I'll give it a shot. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Share Posted January 3, 2010 which variable you say will be different? <?php selecting=".$_GET['selecting']." ?> Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 Instead of changing all my hrefs in my page, could I just change the target page variable to something like $targetpage = 'category.php?selecting=' . $_GET["selecting"] . ' & '; Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 $selecting from page one will be different Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 3, 2010 Share Posted January 3, 2010 Instead of changing all my hrefs in my page, could I just change the target page variable to something like $targetpage = 'category.php?selecting=' . $_GET["selecting"] . ' & '; Yes, if the pagination script adds to the end of the url, that should work fine. But you have to remove the spaces around the ands. $targetpage = 'category.php?selecting=' . $_GET["selecting"] . '&'; Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 3, 2010 Author Share Posted January 3, 2010 And then here is how it is used <a href='$targetpage?page=$counter' .........etc....... Still having problems with this though $targetpage = 'category.php?selecting=' . $_GET["selecting"] . '&'; 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.