Jump to content

Archived

This topic is now archived and is closed to further replies.

cssmatt

Sorting search results into blocks

Recommended Posts

im currently making a search facility, and i have come across the problem of having too many results on a single page.

I know the way around this is to display the results into sets of 10 or so, and provide links to "next page" or "11 - 20" etc.

But im not sure exactly how i would go about this. Would the links at the bottom of each page have to link to a separate page which performed the search again, but used the SQL LIMIT function to say LIMIT 10,20 or something along those lines?

Anyone know of any tutorials that cover this??

Share this post


Link to post
Share on other sites
As if by magic....

[a href=\"http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php\" target=\"_blank\"]Pagination[/a]

Share this post


Link to post
Share on other sites
cheers, thats what i was looking for!!

Now i have another problem! My search sql is playing up! For example, if i search for the word "stan", i know that this only has one occurance in the table im searching. When the search is performed, it brings back 5 results. Each of the results links to the correct entry, but it prints every row in the table in the process (hence bringing back 5 results)

Is there a problem with the query im using?

[code]
$sql = "SELECT table1.user_name, table1.user_id FROM table1, table2
WHERE table2.description LIKE '%" .  $_POST[keywords] . "%'
AND table1.user_id = table2.user_id
AND table2.group_id = '2'";[/code]

Share this post


Link to post
Share on other sites
If table2 has 5 records that match the id in table1 then you get five rows returned when you you join the tables.

Use the DISTINCT keyword

[code]
$sql = "SELECT DISTINCT table1.user_name, table1.user_id FROM table1, table2
WHERE table2.description LIKE '%" .  $_POST[keywords] . "%'
AND table1.user_id = table2.user_id
AND table2.group_id = '2'";[/code]

Share this post


Link to post
Share on other sites

×

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.