Jump to content

Go back to search result


I-AM-OBODO
Go to solution Solved by Barand,

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>";
?>
 
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by dalecosp
  • Like 2
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.