I-AM-OBODO Posted January 29, 2018 Share Posted January 29, 2018 Hi all, How can i go back to a search results after viewing a link on one of the search result. [search Result] $stmt = $pdo->query(" SELECT * FROM tablename WHERE tablename.position LIKE '%$position%' AND tablename.industry LIKE '%$industry%' "); $stmt->execute(); echo "<table width='100%' class='table-responsive table-hover table-condensed table-striped'>"; echo "<tr> <th bgcolor='#444444' align='center'><font color='#fff'>SN</th> <th bgcolor='#444444' align='center'><font color='#fff'>Firstname</th> <th bgcolor='#444444' align='center'><font color='#fff'>Lastname</th> <th bgcolor='#444444' align='center'><font color='#fff'>Email</th> <th bgcolor='#444444' align='center'><font color='#fff'>Position Applied</th> <th bgcolor='#444444' align='center'><font color='#fff'>Employee Position(Current)</th> <th bgcolor='#444444' align='center'><font color='#fff'>State/Province</th> <th bgcolor='#444444' align='center'><font color='#fff'>Country</th> <th bgcolor='#444444' align='center'><font color='#fff'></th> <th bgcolor='#444444' align='center'><font color='#fff'></th> </tr>"; while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo "<tr><td>"; echo $i++; echo "</td><td>"; echo $row['firstname']; echo "</td><td>"; echo $row['lastname']; echo "</td><td>"; echo $row['email']; echo "</td><td>"; echo $row['position_applied']; echo "</td><td>"; echo $row['employee_position']; echo "</td><td>"; echo ucwords($row['state']); echo "</td><td>"; echo $row['country']; echo "</td><td>"; echo "<a href='ApplicantProfile?id={$row['email']}'>view more</a>"; echo "</td></tr>"; } echo "</table>"; After viewing ApplicantProfile and i want to go back to the search result, it shows empty without the results? Thanks Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 29, 2018 Share Posted January 29, 2018 Do you mean that you want the table that is built from a query to be available for the next view by the user? IE, after clicking on one and looking at that, you want to send the user back to the same webpage with the same results showing again? How are you trying to do this? I don't see what is wrong from your post. Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted January 29, 2018 Author Share Posted January 29, 2018 Do you mean that you want the table that is built from a query to be available for the next view by the user? IE, after clicking on one and looking at that, you want to send the user back to the same webpage with the same results showing again? How are you trying to do this? I don't see what is wrong from your post. yes thats exactly what i want to archieve. but when i click back button, the search result is expired and it blank Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 30, 2018 Share Posted January 30, 2018 What is your 'back' button DOING? That's what I am looking for. Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted January 30, 2018 Author Share Posted January 30, 2018 What is your 'back' button DOING? That's what I am looking for. Ok. I did not include the ApplicantProfle page cos i feel it straight forward. But is something like this: <a href="Search-Result.php">Back</a> <?php $stmt = $pdo->query(" SELECT * FROM tbl_name LEFT JOIN $tbl_name2 ON tbl_name.email = tbl_name2.email WHERE tbl_name.email = '$_GET[id]' "); $row = $stmt->fetch(PDO::FETCH_ASSOC); ?> <h4>Personal Details</h4> <?php echo "<table class='table table-bordered' >"; echo "<tr><td width='30%'><strong>Firstname</strong>"; echo "</td><td>"; if(isset($row['firstname'])) echo $row['firstname']; echo "</td>"; echo "<tr><td> <strong>Middle Name</strong>"; echo "</td><td>"; if(isset($row['middle_name'])) echo $row['middle_name']; echo "</td>"; echo "<tr><td> <strong>Surname</strong>"; echo "</td><td>"; if(isset($row['lastname'])) echo $row['lastname']; echo "</td>"; echo "<tr><td> <strong>Gender</strong>"; echo "</td><td>"; if(isset($row['gender'])) echo $row['gender']; echo "</td>"; echo "<tr><td> <strong>Date of Birth</strong>"; echo "</td><td>"; if(isset($row['dob'])) echo $row['dob']; echo "</td>"; echo "<tr><td><strong>Email</strong>"; echo "</td><td>"; if(isset($row['email'])) echo $row['email']; echo "</td>"; echo "<tr><td> <strong>Title</strong>"; echo "</td><td>"; if(isset($row['title'])) echo $row['title']; echo "</td>"; echo "<tr><td> <strong>Phone</strong>"; echo "</td><td>"; if(isset($row['phone1'])) echo $row['phone1']; echo "</td>"; echo "<tr><td> <strong>Phone</strong>"; echo "</td><td>"; if(isset($row['phone2'])) echo $row['phone2']; echo "</td>"; echo "<tr><td><strong>Residential Address</strong>"; echo "</td><td>"; if(isset($row['residential_address'])) echo ucwords($row['residential_address']); echo "</td>"; echo "<tr><td><strong>City</strong>"; echo "</td><td>"; if(isset($row['city'])) echo ucwords($row['city']); echo "</td>"; echo "<tr><td><strong>State / Province</strong>"; echo "</td><td>"; if(isset($row['state'])) echo ucwords($row['state']); echo "</td>"; echo "<tr><td><strong>Country</strong>"; echo "</td><td>"; if(isset($row['country'])) echo ucwords($row['country']); echo "</td>"; echo "<tr><td><strong>Zip</strong>"; echo "</td><td>"; if(isset($row['zip'])) echo $row['zip']; echo "</td>"; echo "<tr><td><strong>Specialization</strong>"; if(isset($row['specialization'])) echo $row['specialization']; echo "</td>"; echo "<tr><td><strong>Personal Pitch</strong>"; echo "</td><td>"; if(isset($row['personal_pitch'])) echo $row['personal_pitch']; echo "</td>"; echo "<tr><td><strong>Skills & Competences</strong>"; echo "</td><td>"; if(isset($row['skills_competences'])) echo $row['skills_competences']; echo "</td>"; echo "<tr><td><strong>Achievements</strong>"; echo "</td><td>"; if(isset($row['achievements'])) echo $row['achievements']; echo "</td>"; echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 30, 2018 Share Posted January 30, 2018 You could pass the search criteria through your ApplicantProfile link. Then the profile page could use the search criteria to create the back button. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 30, 2018 Share Posted January 30, 2018 A couple things: 1. How are the search criteria defined? Based on this code it appears you have position and industry as search criteria. $stmt = $pdo->query(" SELECT * FROM tablename WHERE tablename.position LIKE '%$position%' AND tablename.industry LIKE '%$industry%'"); How does the user select those criteria? Are they sent via POST, GET, other? Depending on how those fields are received and how you load the page, using the browser's back button should normally work to show the previous results. But, not knowing all the intricacies you have I can't provide a knowledgeable answer. 2. Another approach is to save criteria as session data. So, if a user opens the search page, it first checks if new search criteria was selected. If so, it uses that. Otherwise, it will use any search data saved in the session. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted January 31, 2018 Share Posted January 31, 2018 (edited) Search should be performed using "redirect-after-POST", aka PRG (Post-Redirect-Get). As such, there should be a parameter in the URL of the search results page, such as a distinct searchid, which can be used by the search script to recall terms and possibly even the result set. Edited January 31, 2018 by dalecosp 2 Quote Link to comment Share on other sites More sharing options...
Sepodati Posted January 31, 2018 Share Posted January 31, 2018 You have to remember or pass $industry and $position back to Search-Result.php. Keeping them in a session may work. If they are passed as a part of a form, prefer those values, but otherwise look in a session for "previous" values of the two search terms. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted January 31, 2018 Share Posted January 31, 2018 Why program a back button when the browser already has one, though? Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted January 31, 2018 Author Share Posted January 31, 2018 A couple things: 1. How are the search criteria defined? Based on this code it appears you have position and industry as search criteria. $stmt = $pdo->query(" SELECT * FROM tablename WHERE tablename.position LIKE '%$position%' AND tablename.industry LIKE '%$industry%'"); How does the user select those criteria? Are they sent via POST, GET, other? Depending on how those fields are received and how you load the page, using the browser's back button should normally work to show the previous results. But, not knowing all the intricacies you have I can't provide a knowledgeable answer. 2. Another approach is to save criteria as session data. So, if a user opens the search page, it first checks if new search criteria was selected. If so, it uses that. Otherwise, it will use any search data saved in the session. Yes the position and industry are the search conditions. The user select the criteria from a list in the dropdown menu via a post. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 31, 2018 Share Posted January 31, 2018 see php's http_build_query() to help forming the query-string part of URLs with the existing $_GET parameters and any new get parameter per link. btw - you should NOT use email addresses as the link to your user's information. these will get indexed by search search engines and scraped by spammers. you should use the auto-increment id column from the users table as the user id in the links. 1 Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 1, 2018 Solution Share Posted February 1, 2018 You should be passing parameters to a search page via GET and not using POST Yes the position and industry are the search conditions. The user select the criteria from a list in the dropdown menu via a post. 2 Quote Link to comment Share on other sites More sharing options...
dalecosp Posted February 1, 2018 Share Posted February 1, 2018 You should be passing parameters to a search page via GET and not using POST Yes! That is the essence of my answer above. Redirect-after-POST: User posts search form, handler determines if query is valid. If so, search term (and optionally, some clue as to the result) is saved in the DB and the ID of the saved datum is fed back to the script. Header() is used to send the client to a search page with this ID attached, page reads the search ID and grabs the terms and returned items and displays them. It could probably be implemented in the SESSION, but then it's not as "shareable". With a saved searchID, if you desire, you can re-use the URL to grab the same set of search results for any arbitrary period of time, and the concept of URI permanence is preserved. 1 Quote Link to comment Share on other sites More sharing options...
kicken Posted February 2, 2018 Share Posted February 2, 2018 Yes! That is the essence of my answer above. Redirect-after-POST: ... Unless your search has a massive amount of inputs, there shouldn't be a POST step at all. Your form should bet GET from the beginning. It makes everything much simpler, and going back to the results is just a matter of clicking the browser back button. Quote Link to comment Share on other sites More sharing options...
I-AM-OBODO Posted February 2, 2018 Author Share Posted February 2, 2018 Thanks all. I decided to change my form method from POST to GET. Thanks Quote Link to comment Share on other sites More sharing options...
dalecosp Posted February 2, 2018 Share Posted February 2, 2018 Unless your search has a massive amount of inputs, there shouldn't be a POST step at all. Your form should bet GET from the beginning. It makes everything much simpler, and going back to the results is just a matter of clicking the browser back button. Potentially TOO simple. I want to make sure that a user is coming from inside our site, for the most part, when doing a search. Even the good bots will abuse a page if they can construct anything they want via GET. The bad ones will bring your server to its knees if they can. 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.