PHP Managing search results PHP/HTML
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Managing search results PHP/HTML

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    5

    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)

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,867

    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.

  3. #3
    Join Date
    Oct 2011
    Posts
    5

    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.

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,867

    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.

  5. #5
    Join Date
    Oct 2011
    Posts
    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.

  6. #6
    Join Date
    Oct 2011
    Posts
    5

    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

  7. #7
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,867

    Re: Managing search results PHP/HTML

    I'll respond out of order...

    Quote Originally Posted by lfreytag View Post
    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.


    Quote Originally Posted by lfreytag View Post
    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.

  8. #8
    Join Date
    Oct 2011
    Posts
    5

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center