Jump to content

Recommended Posts

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'];

Link to comment
https://forums.phpfreaks.com/topic/163426-post-and-get-method-on-the-same-page/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.