how to do a search in MySQL table?

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmjared
Posts: 10
Joined: Thu Mar 24, 2011 5:20 am

how to do a search in MySQL table?

Post by jmjared » Fri Jul 08, 2011 6:05 am

Hi everyone,

I've been trying to be able to search for certain words in MySQL table and get the words that match the search criteria into a field...

any help would really be appreciated (i'm about to kill myself with this...)

Thanks!!!

JM

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: how to do a search in MySQL table?

Post by bangkok » Fri Jul 08, 2011 7:12 am

You should find a lot of examples (working scripts) on this forum.

Or post your current script so we can have a look.

jmjared
Posts: 10
Joined: Thu Mar 24, 2011 5:20 am

Re: how to do a search in MySQL table?

Post by jmjared » Fri Jul 08, 2011 8:55 am

Thanks..

This is what I have so far..

global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if

put "SELECT event FROM postings" into tSQL

put revDataFromQuery(tab, cr, gConnectionID, tSQL,) into tData

if item 1 of tData = "postings" then
answer error "There was a problem quering the database:" & cr & tData
else
put tData into field "SEARCH LIST"
end if

I'm able to get a column from the table but I want to be able to search for specific items within the column and make those the only one to show on the field..

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: how to do a search in MySQL table?

Post by SparkOut » Fri Jul 08, 2011 9:59 am

It depends on the size of the data that is returned I suppose, but you may find that Livecode, with its excellent text chunk handling makes as good a job of extracting the data you want to display from the values returned in the tData variable than it would be to filter the data in the SQL query. Nevertheless, there is no point in needlessly bottlenecking the application by returning unwanted data so you probably want to have your SQL query something like:

Code: Select all

put "birthday" into tEvent -- or whatever text you are looking to match
put "SELECT event FROM postings WHERE event LIKE  '%" & tEvent & "%'" into tSQL
The result should be a SQL query that looks like:
SELECT event FROM postings WHERE event LIKE '%birthday%' and will return data from records where the event column contains the word "birthday" at any point in the string.

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to do a search in MySQL table?

Post by Klaus » Fri Jul 08, 2011 1:54 pm

Hi JM,

looks like you need to learn a little SQL!

Check this, which also got me started with SQL :D
http://www.w3schools.com/sql/default.asp


Best

Klaus

jmjared
Posts: 10
Joined: Thu Mar 24, 2011 5:20 am

Re: how to do a search in MySQL table?

Post by jmjared » Wed Jul 13, 2011 9:34 am

awesome! that was very helpful... THANKS!

Post Reply