Jump to content


Photo

Sorting search results into blocks


  • Please log in to reply
3 replies to this topic

#1 cssmatt

cssmatt
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 06 April 2006 - 10:30 AM

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??

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 06 April 2006 - 11:07 AM

As if by magic....

[a href=\"http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php\" target=\"_blank\"]Pagination[/a]
follow me on twitter @PHPsycho

#3 cssmatt

cssmatt
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 06 April 2006 - 11:38 AM

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?

$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'";


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 April 2006 - 11:40 PM

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

$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'";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users