•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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??
$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??
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
try to extend your query with order by:
or:
whichever is correct.
$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
http://ryantetek.wordpress.com
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:
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";
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 1
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsense adult advertising algorithms blog blogging bomb book business coding competition copyright daniweb development engine environment forum gasoline gentoo google hybrid internal combustion engine legal linux malware marketing mcafee microsoft monetization msn news pagerank php privacy publishing revenue search security seo sex silverlight software spam spyware support technical web webmaster wiki yahoo
- search engine script (Existing Scripts)
- The secrets of google search engine ranking (Promotion and Marketing Plans)
- Ask Jeeves Launces TRUST anti-fraud Search Engine (Search Engine Optimization)
- Latest Jupiter Media Tips & Stats from Search Engine Strategies 2005, New York (Search Engine Optimization)
- How to export excel data to a search engine? (MS Access and FileMaker Pro)
- Deleting subjects in a search engine window (Web Browsers)
- Using Search Engine Friendly PHP URLs (PHP)
Other Threads in the PHP Forum
- Previous Thread: Help needed to integrate outlook calendar
- Next Thread: How can i add textbox values to listbox values....


Linear Mode