LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2006, 10:08 PM   #1
crewblunts
Member
 
Registered: Jan 2004
Location: Connecticut, USA
Distribution: Slackware & Ubuntu
Posts: 53

Rep: Reputation: 15
PHP and MySQL LOCATE


Hello all,
I have a string in column exerciseTypes in a database named exercises. The string contains values separated by '&'. I am trying to search the database for all instances where a specific substring is located inside of the string contained in column exerciseTypes.

ex:
string: "pullups&situps&calf raises"
subdtring i am looking for: 'situps'

Right now I am selecting all of the rows in the database and searching for the substring using the strpos() function in PHP. I know there must be a more efficient way of doing this. I have looked into the LOCATE and am not sure if it is correct for this application. Any help would be appreciated.

Thanks in Advance,

Phil V
 
Old 04-20-2006, 03:52 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
If I understand you problem correctly that would appear to be the right thing to do, it will probably look like this:
Code:
SELECT * FROM mytable WHERE LOCATE('situps', exerciseTypes)>0
 
Old 04-20-2006, 10:48 PM   #3
crewblunts
Member
 
Registered: Jan 2004
Location: Connecticut, USA
Distribution: Slackware & Ubuntu
Posts: 53

Original Poster
Rep: Reputation: 15
oh man...thanks that is much easier to read. Thanks again for your help

-Phil V
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php-mysql dependancy problem after nitemare mysql upgrade. RHEL4 andrewc Red Hat 1 01-03-2006 04:16 PM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 02:54 PM
Installing MySQL.4.0.17 and php support for Mysql on RedHat 9.0 Neha Linux - Software 13 12-29-2003 12:06 AM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 08:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration