Search bars
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Search bars
Hi I'm new to livecode and would like to add a search bar to a card that will allow me to search a specific online database, is this possible and if so how would I go about this?
Look forward to hearing your responses! Thanks!
Look forward to hearing your responses! Thanks!
Re: Search bars
Hi,
For now, I would forget about "search bar" and concentrate on writing a script that connects to the database and retrieves the required data.
What can you tell us about the database? Do you have a link? Do you own the server where the database is located? What types of access to the database are available?
Kind regards,
Mark
For now, I would forget about "search bar" and concentrate on writing a script that connects to the database and retrieves the required data.
What can you tell us about the database? Do you have a link? Do you own the server where the database is located? What types of access to the database are available?
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Search bars
Hi, Whytey. Do you want to search an existing online database? Here's an example that searches these forums. Simply create a new stack and add a text entry field (the single line field) and a scrolling field (the multiline field). Change the names of the fields to "Search" and "Results" respectively.
Now put the following code into the "Search" field;
Now type something into the search field, press 'enter' or 'return' and the results are put into the results field. Just a simple example of how to start building a search bar, but hopefully this will help 
Now put the following code into the "Search" field;
Code: Select all
on enterinField
searchForums
end enterinField
on returnInField
searchForums
end returnInField
command searchForums
set the htmlText of field "Results" to URL ("http://forums.runrev.com/search.php?keywords=" & urlEncode(the text of me))
end searchForums

LiveCode Development & Training : http://splash21.com
Re: Search bars
Wow thank you so much for these really helpful answers I will definitely give this a go I have just generated a simple app that works really well but I really have zero coding ability so just stumbling through livecode as I go! For this new idea, the database I want to link to is pubmed, a database where all scientific papers are stored. Each paper published has summaries/abstracts, I would like to retrieve the abstracts from the first five entries and put them into five text boxes. Does that make sense?
Re: Search bars
Hi Splash21, I've just tried your suggestion, the code works brilliantly but with the pubmed url I get an error. On pubmed the first page is a search engine like google where you enter text to search the database do I need something in the code that says copy the text into pubmed's search engine first then bring down the results?
Thanks for your help, this is brilliant!
Thanks for your help, this is brilliant!
Re: Search bars
You need to do a little research. For this forum, I right clicked on the search box and selected 'Inspect element' (I'm using Chrome) to find the name of the search box. Some sites are fussy as to whether GET or POST is used (http://www.w3schools.com/tags/ref_httpmethods.asp), but these forums don't seem to mind.
Check out the entries for 'URL' and the 'urlEncode' function in the LiveCode dictionary...
Check out the entries for 'URL' and the 'urlEncode' function in the LiveCode dictionary...
LiveCode Development & Training : http://splash21.com
Re: Search bars
I just had a little look at pubmed... the search 'term' is passed in the URL (GET method) ....
So if you change the relevant line in the field script to
then you get what I think you're after.
You just have to do a bit more work to pick out the pieces you are interested in.

So if you change the relevant line in the field script to
Code: Select all
set the htmlText of field "Results" to URL ("http://www.ncbi.nlm.nih.gov/pubmed/?term=" & urlEncode(the text of me))
You just have to do a bit more work to pick out the pieces you are interested in.

LiveCode Development & Training : http://splash21.com
Re: Search bars
Hi Splash, works a dream now thank you! What is the code I would need to use for picking out various parts?
Thanks this is brilliantly helpful!
Thanks this is brilliantly helpful!
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Search bars
PubMed provides an API, which IIRC uses XML so it may simplify some aspects of parsing returned values:
http://www.ncbi.nlm.nih.gov/books/NBK25500/
http://www.ncbi.nlm.nih.gov/books/NBK25500/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Search bars
Hi, I'm still not sure how quite to parse the results. It seems the titles have a 244 number in front of them could we use this to sort through the junk text? What is the code that would allow me to grab each title starting with 244 and put them into a separate box?
here's an example of what I mean.
Select item 244068682.
p53-Dependent Suppression of Genome Instability in Germ Cells.
Otozai S, Ishikawa-Fujiwara T, Oda S, Kamei Y, Ryo H, Sato A, Nomura T, Mitani H, Tsujimura T, Inohara H, Todo T.
Mutat Res. 2014 Jan 6. pii: S0027-5107(13)00215-7. doi: 10.1016/j.mrfmmm.2013.12.004. [Epub ahead of print]
PMID:
ideally I would like to grab everything from this up until [Epub ahead of print].
I hope you can help! I look forward to hearing from you!
here's an example of what I mean.
Select item 244068682.
p53-Dependent Suppression of Genome Instability in Germ Cells.
Otozai S, Ishikawa-Fujiwara T, Oda S, Kamei Y, Ryo H, Sato A, Nomura T, Mitani H, Tsujimura T, Inohara H, Todo T.
Mutat Res. 2014 Jan 6. pii: S0027-5107(13)00215-7. doi: 10.1016/j.mrfmmm.2013.12.004. [Epub ahead of print]
PMID:
ideally I would like to grab everything from this up until [Epub ahead of print].
I hope you can help! I look forward to hearing from you!