My website allows visitors to search for homes (using PHP and MySql). After the search, they are presented with a list of matches which they can click on to see the detail page for that home. To see the next home, they currently have to click back, then click on the next home in the search results list they want to view.
I would like to make it so that once they have clicked on one home to view the details, they would have a "Next Home" and "Previous Home" link/button to use to navigate the results set without having to go back to the search results page.
I've seen this done, but can't get my head around how to do it. I assume you have to save the recordset from the initial search somewhere, and then recall it on the details page. And you'd have to know that you were looking at the xth home out of Y homes.
Can anyone give me a broad overview of how this would work? Do I save the initial search results in a temp MySQL table and pass that table name to the details page? Or use a session variable to hold the results set? Keep in mind that a visitor could make several different searches during their session.
Any assistance would be most appreciated,
Tom
When I've done this, I've saved the details of the current search in SESSION, and then requeried the database when I've needed to - so you can query it on the detail page to generate a Next and Previous link, and so on. I normally use a SESSION variable called 'parameters', and add the whole of the SQL WHERE statement to it.
If someone's making multiple searches, this will let them make one at a time - subsequent searches will over-write what's already in there. If your users are going to be making multiple searches at the same time using different parameters, you'll need to find a way to differentiate the parameters for each search. You can give each set a unique name by prefixing it with a call to uniqid, and you'll then need to make sure you pass the unique identifier to the detail page, so it can work out which set of parameters it needs to run.
Related
I am a beginner programmer/coder who is currently trying to get to grips with HTML and PHP. I currently have a locally hosted searchable database that (when used) brings up a list of the first twenty entries that correspond to your search terms, with buttons to send you to the next page, last page, etc. (you know... pages...) The search outputs information into the URL ([url]?q=Alphonse&f=Elric etc). I have two problems with this at the moment.
Problem A:
My URL contains information that is unused. If I don't put anything into the search term it simply comes out with "q=&x=&f=..." etc. This makes the URL absurdly long even on the most simple searches.
Can this be cleaned up through just php?
Would this method be different if I end up hosting this online?
Problem B:
The way my paging functions is to send the user to the following link '.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&pn='.$nextPage.'. This outputs the current link but with "pn=1" at the end (Or whatever relevant page they click).
This method itself makes the URL quite messy. If they click through multiple pages, and perhaps go back and forth, the link ends up having "pn=1&pn=2&pn=3&pn=1...." etc at the end. I assume that this will be answered by the first query, but it is slightly different in that this is information that is actually present.
How do I remove this superfluous information, and just keep the (final) relevant one?
I am thinking that I can use parse_str to turn the URL into an array, then delete each entry of the array that are empty, then create a new string out of that array and make that the link the search/next page button goes to.
Does that sound like it would work? If so, how do I delete those specific array entries, and how would that array then be stored? Would the array lose those entries and calling a deleted entry "$array['1']" for example result in an error, or does deleting entries in an array move everything up one to fill the gap?
Apologies if I'm asking too many different things in one post here!
The title may be a bit awful as I'm really not sure how to describe what I'm trying to achieve without using lots of words.
I'm currently building an events website. This website has the option for users to create their own events which can be added to a big list of upcoming events that other users have submitted.
What I want to do is be able to have a user create an event and have the details of the event stored in an SQL database (which I've successfully done), I want to be able to then have a large list of events on a separate page the details of which are pulled from the server dynamically using PHP and SQL (I've also successfully done this). The part I am struggling with however is being able to create unique pages (or a single dynamic page) that displays a more detailed look at the event, such as age restrictions etc etc, which cannot be displayed on the big list which displays all the available events.
I figured that this could be done using a unique eventID, which is something the SQL database already includes and autoincrements with each new event entry. What I'm really not sure about is how I'd be able to pass that eventID through the link to the more detailed page so that the detailed page can be created displaying all of the details of the event.
I'm not even sure if this idea will work at all. Would having a page with a unique URL that is created on event submission that has a more in-depth look at the details of the event be a better idea? How would I go about creating unique URL webpages that correspond to each event on event submission?
I'm really not sure how I need to go about this at all, so I need some help and pointing in the right direction.
Here's a kind of TLDR:
1) Events website
2) All events on the website are displayed on a single page that has minimal detail about each event (title, date, location) BUT has a link to a page that displays the event in more detail.
3) User can select an event from the list and click on that event's unique HTML link to more detailed page
4) More detailed page displays event in more detail by pulling event's unique information from the database
Feel free to ask any questions at all as I know this probably isn't the easiest idea to get across
When creating the links from the general listing page to the detail page, simply include the id in the link. For example:
<A HREF="mysite.com/detail.php?id=3>Big Event</A>
In detail.php then, you'll find the id in $_GET['id'].
There is a similar question here Best way to implement <next>, <prev> element links from search list
But I'm not satisfied with that answer, and my case is slightly different, and I want to know the best way more commonly.
I have a search page, let's say, searching poems. (currently the data is from mysql, but I'm planning to index them into apache solr)
Each result on the search result page (let's say, /search?keyword=flower&author=john) is a link, which you can click and will be redirected to the poem detail page.
(let's say, /poem/1234/This-is-the-best-poem)
Now I want "prev" and "next" links on the detail page if the page is clicked from a search result page. and it uses the same order of the search results.
What I can think is to add full search parameters to the detail page, so the "detail page with pagination" actually is a search results but perpage = 1.
But I have to do the full query everytime showing a poem detail page.
I wonder is there a better way ?
Thanks and apologize for my bad English.
As for the Solr part of this, you can use DeepPaging, take a look here:
http://heliosearch.org/solr/paging-and-deep-paging/
You get a 'cursorMark' from Solr when you use DeepPaging which works
like sort of a book mark for your next query results.
You will have to requery, but you will stay in the same result set using that flag,
so when you do this only for the next document you will have to get only one row,
remember your current position where to start,
save the cursor mark and repeat all of that for the next.
By remembering previous cursorMarks you can also go back.
Regards,
Markus
You have to get the poem from the db for the detail. But the rest of the parameters can be passed on from the list page, including a list (array) of poem IDs retrieved in the paged list. You could use this until you reach the end of list, to retrieve the next page list.
You might also want to consider caching options available on the server. APC extension is common on PHP.
I have completely no idea where to start so I apologise about the lack of code presented to you.
My problem is - I have a page of information, ordered by ID (gathered from the database). These ID's are referenced from another page to which the user clicks on a link and it takes them to the page with the information on, how ever, there could be potentially hundreds of ID's on that page - So I need to reference each specific ID so when the user clicks, it will take them to the exact position of the ID.
I understand its something like localhost:8888/index.html#id3 etc..
But i'm struggling to understand how to reference for a PHP Variable.
Many thanks in advance.
You would use anchors, so for example, on the page where you list your information, attach an anchor to it such as #id1, then on your links page, you would place the #id1 at the end of the url results.html?#id3
I have searched online for this issue, but the results are mostly based around Excel.
I have a webpage that has a list of videos. Every time someone clicks on a link, they are taken to a separate page where they can view a video. I have a table in my mysql database that links video id to views. I would like to increment the views column every time someone clicks on the link.
I know how to do this on the database side, but I am trying to figure out how to trigger the DB operation via PHP. I thought about having a script at the top of the page that calls the stored procedure to update the tally everytime the page is loaded, but the problem with this is that the video doesn't start automatic ally when the page loads. Users have to manually click on "play".
Why not write an Update query on the table which gets called everytime a link is clicked?
It is a little confusing where you want to increment the counter. You give three situations:
When a user clicks a link to a particular video's page
When a user loads a particular video's page
When a user clicks play on a video
1 & 2 wouldn't give an accurate count of those who actually watched the video, so I'll choose that you meant 3.
It depends on your video player then. If the player has a way to hook a javascript function to the start of a video, then you can use that to make an ajax request back to a server page that updates your database. If the player has no hooks then you're limited to on page load, which will be less reliable.
Does this help? If I miss understood the question, please clarify by updating the question or adding comments. PS. adding code of what you've tried goes a long away as well.