ArizonaJohn Posted June 23, 2009 Share Posted June 23, 2009 Hello, I would like to make a variable $find equal to $_POST['find'] if the user is landing on the page after using the POST method, but on the same page make $find equal to $_GET['find'] if the user is landing on the page after using the GET method. How do I do that? Thanks in advance, John $find = $_GET['find']; $find = $_POST['find']; Quote Link to comment https://forums.phpfreaks.com/topic/163426-post-and-get-method-on-the-same-page/ Share on other sites More sharing options...
Alex Posted June 23, 2009 Share Posted June 23, 2009 Are they for the same thing? If so just use $_REQUEST which is like a hybrid of the two. Quote Link to comment https://forums.phpfreaks.com/topic/163426-post-and-get-method-on-the-same-page/#findComment-862261 Share on other sites More sharing options...
elis Posted June 23, 2009 Share Posted June 23, 2009 Not tested, but something like this? <?php if(isset($_POST['find'])) { $find = $_POST['find']; } elseif(isset($_GET['find'])) { $find = $_GET['find']; } Quote Link to comment https://forums.phpfreaks.com/topic/163426-post-and-get-method-on-the-same-page/#findComment-862266 Share on other sites More sharing options...
ArizonaJohn Posted June 23, 2009 Author Share Posted June 23, 2009 Thanks everyone for the answers... they all seem good/correct to me. But they didn't solve the larger problem that I was trying to solve: implementing pagination. I guess I'll just put pagination on the back burner for now. Quote Link to comment https://forums.phpfreaks.com/topic/163426-post-and-get-method-on-the-same-page/#findComment-862295 Share on other sites More sharing options...
elis Posted June 24, 2009 Share Posted June 24, 2009 Well, can be a little tricky but here's a code I'm using to print "previous" and "next" links and pull content from the database based on their positions - which could be considered a ghetto form of pagination, if you tweaked it a bit, it might lead you in the direction you want. <?php $counter = 0; //counter used to count results - goal is to print 10 results per "page" if($_GET['end']) { //if "end" is set in the url, assign it to perpage $perpage = $_GET['end']; } else { $perpage = 10; //if "end" is not set in the url, end the page at 10 results } if($_GET['start']) { //same as above, but for the "start" number of the query $startpage = $_GET['start']; } else { $startpage = 0; } $sqlRM = "SELECT * FROM relationshipManagement WHERE candidates_id = '$id' ORDER BY date DESC LIMIT $startpage, $perpage"; $conn->open(); $stmtRM = $conn->prepare($sqlRM); $stmtRM->execute(); if($stmtRM->rowCount() > 0) { while ($rm = $stmtRM->fetch(PDO::FETCH_ASSOC)) { //removed, not of any importance if($rm['notes']) { // removed, not of any importance $counter++; //increment counter for each row pulled from the database } } if($_GET['start'] > 0) { //if "start" is greater than 0, then subtract 10 to create a "previous" link and allow the user to go to the "previous" set of results $start = $_GET['start'] - 10; $per= $_GET['end'] - 10; echo '<span align="right"><a href="?id=' . $id . '&start=' . $start . '&end=' . $per . '"> << Prev </a></span>'; } if($counter >= 10) { //if the counter is greater or equal than 10, then set "start" as the previous "end" number and add 10 to the new end number - creates a "next" page for the next 10 results $startpage = $perpage; $perpage += 10; echo '<span align="left"><a href="?id=' . $id . '&start=' . $startpage . '&end=' . $perpage . '">Next >> </a></span>'; } echo '</div></div>'; ?> So this works as: http://yoursite.com?start=20&end=30 the code manipulates "start" and "end" to retrieve the next and previous set of results from the database. Adding numbers to create actual pagination would probably involve creating a second counter and printing the actual number instead of "next" and "previous" links. Also, the above isn't sanitized at all. If you choose to mimic it, remember to add security. Quote Link to comment https://forums.phpfreaks.com/topic/163426-post-and-get-method-on-the-same-page/#findComment-862608 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.