-
December 8th, 2011, 10:51 AM
#1
Managing search results PHP/HTML
Hi. I'm making a web page to search my photos.
On the client side, it is a simple form based page written in Dreamweaver. User types in a word and hits a button.
On the server side, it runs on PHP. Search is performed and results returned to form on client.
My page will show up to four images. If the search returns more than that, is what my question is about. I can stage the result and re-do the search each time, or save all the returned image numbers from the original search, to make only one call to php for actual search. Not sure how much data I can put into a hidden form. The results could be up to about 500 images, each requiring an int to be saved on the hidden form.
I want to keep everything on the form and not use parameters visible on the invocation line. I realize this is not perfect but it works for me. Any suggestions. Thanks, Larry (Olympia, WA)
-
December 8th, 2011, 03:27 PM
#2
Re: Managing search results PHP/HTML
I'm confused as to what your question is. Are you trying to do paging with your search results? If so, just use the LIMIT method in your SQL query.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
December 8th, 2011, 07:16 PM
#3
Re: Managing search results PHP/HTML
Hi. I want to show the first four results, then when user hits more, do the next four, etc. This requires a resubmit of the form each time. Do I have to do the search again each time, or can I just keep getting the next four results somehow. Will PHP remember where I am at or is it a fresh start each time. Thanks.
-
December 10th, 2011, 12:53 PM
#4
Re: Managing search results PHP/HTML
Unless you cache the query results, they will not be remembered. But, if your query is just returning 4 results, then there's no reason to cache. Simply use the LIMIT method and return the proper results. This is known as paging.
PHP Code:
// http://www.site.com/path/to/file.php?page=x $page = (isset[$_GET['page']]) ? $_GET['page'] : 1; // if none specified...it will be page = 1 $numberOfResults = 4; $offset = ($page - 1) * $numberOfResults; // calculate the offset for showing results
$query = "SELECT * FROM table LIMIT $offset, $numberOfResults";
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
December 11th, 2011, 11:50 AM
#5
Re: Managing search results PHP/HTML
Thank you very much...I will be working with this method it will take a while to see if I am getting there. I appreciate the help.
-
December 12th, 2011, 12:24 PM
#6
Re: Managing search results PHP/HTML
Peej, Yes this is working now. Thanks again. Yet I have to ask a few follow ups.
1. To get the number of matches, I still need to do the query without the LIMIT. After that occurs, I can grab the first four responses as well.
2. For further output, I do the query again using limit offset,4 as you suggested. Works fine.
3. I fear this approach may be very inefficient. For some terms, there are hundreds of returned results, and the query is repeated many times. Can I ask MySQL to save the whole result (temporarily) so I can refer into it piece by piece as needed. Then release the temporary composite when finished. Perhaps it is not inefficient anyway? Thoughts? Thanks again
-
December 12th, 2011, 01:07 PM
#7
Re: Managing search results PHP/HTML
I'll respond out of order...
Originally Posted by lfreytag
3. I fear this approach may be very inefficient. For some terms, there are hundreds of returned results, and the query is repeated many times. Can I ask MySQL to save the whole result (temporarily) so I can refer into it piece by piece as needed. Then release the temporary composite when finished. Perhaps it is not inefficient anyway? Thoughts? Thanks again
Inefficient only in annoyance to the users. I would hate to only receive 4 results. Using the LIMIT means the queries are ridiculously minimal and therefore not pooling resources or time on your database server.
Originally Posted by lfreytag
1. To get the number of matches, I still need to do the query without the LIMIT. After that occurs, I can grab the first four responses as well.
Actually, this would be inefficient. Yes, you would get all the results off the bat, but then you would have to create another storage method to hold all the results and pass it back and forth from pages. This would case page load times to significantly drop!
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
December 12th, 2011, 07:26 PM
#8
Re: Managing search results PHP/HTML
My design is to show four images per screen. I have built my thumbnails
for thispurpose at 40kpixels so they can actually be seen. That is the number of
Images that fits comfortably and neatly. Thanks for your help.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|