User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,970 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,773 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 752 | Replies: 3
Reply
Join Date: Nov 2007
Posts: 2
Reputation: ManOnScooter is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ManOnScooter ManOnScooter is offline Offline
Newbie Poster

Pagination & DB search engine queries

  #1  
Nov 23rd, 2007
I am trying pagination for a database-database search engine - this was the query

$sql = "select id, name from student_adv WHERE name LIKE '%$search%' order by id limit $startIndex, $perPage";
and it worked fine when i had
$search = John

The problem starts when i put $search = John Lennon

I modify my query to
$sql = "select id, name from student_adv WHERE name LIKE '%$search%' or name like '%$w1%' or name like '%$w2%' limit $startIndex, $perPage";

here
$search = John Lennon
$w1= John
$w2=Lennon

But, the result shows the presence in an order which is random, i.e. Lennon is in the result-set array before John Lennon or John,
But, I want the result set array to have John Lennon coming before John & John before Lennon..
So John Lennon Results come first then John and the Lennon

How do I do this??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Pagination & DB search engine queries

  #2  
Nov 24th, 2007
try to extend your query with order by:


$sql = "select id, name from student_adv WHERE name LIKE '%$search%' or name like '%$w1%' or name like '%$w2%' order by name asc limit $startIndex, $perPage";


or:


$sql = "select id, name from student_adv WHERE name LIKE '%$search%' or name like '%$w1%' or name like '%$w2%' order by name desc limit $startIndex, $perPage";


whichever is correct.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Nov 2007
Posts: 30
Reputation: chrelad is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
chrelad's Avatar
chrelad chrelad is offline Offline
Light Poster

Help Re: Pagination & DB search engine queries

  #3  
Jan 1st, 2008
Hi ManOnScooter,

In order to make certain that your results are displayed in order, include a date field or ID field in the order clause after the name:

$sql = "select id, name from student_adv WHERE name LIKE '%$search%' or name like '%$w1%' or name like '%$w2%' order by name, id asc limit $startIndex, $perPage";
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: r4ccoon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
r4ccoon r4ccoon is offline Offline
Newbie Poster

Re: Pagination & DB search engine queries

  #4  
Jan 1st, 2008
try this sql
select * from student_adv where id!='' and match(`student_adv`) against ('\"searchkeyhere\"' IN BOOLEAN MODE)

this sql will search your string in and boolean mode...
for example john doe, this sql will return john abes doe, john mike doe, john william doe...
and not return john axe, doe john, or dei john arc,,

if you want return like with or mode, you can remove double quote and remove in boolean mode.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC