| |||||||||||
| |||||||||||
Loop query Posted by TedH (TedH), 17 September 2006 Hi, trying to match a record in a flat file db.I manage to do that as follows: The db: data.txt ------------------------ 000210|anything 000211|something 000212|wotathing ------------------------ The ID (number) is typed into a form and sent to match script - the core of which is as follows: Code:
It returns it okay but looks like this The Record (000210|anything) No match No match or (depends which record ID is used) The Record No match (000211|something) No match I know I can get rid of the else and only the match returns. But is that correct? Is the script keeping on looping behind the scenes? (it doesn't seem to but I'm not sure) cheers - Ted Posted by admin (Graham Ellis), 17 September 2006 It looks fine, Ted ... the loop will teminate when all the records have been looked through and no process will be left running.If you're only looking for one matching record and can abandon the search once you've found it, add a "last" statement after you've printed the matching record. If your datafile might get large, don't read it all in to a list at the beginning - instead, use a loop of the form while ($rec=<ORGDB>) { which will cause the data to be read, and analysed as it is read. That's different to the scrit you supplied, which read the whole file into a list then processes it item by item - great for a few lines, but not so good if you're going to end up with hundreds of thousands of lines of data. Posted by TedH (TedH), 17 September 2006 Like this Graham?Code:
It seems to work okay. At first I used the last statement with it and it didn't like that. Picks up the record fine. Posted by admin (Graham Ellis), 17 September 2006 Looks fine ... don't know why it didn't work with "last" ...Code:
which really only makes it a bit more effieicnt - stops searching once it's matched. Posted by TedH (TedH), 17 September 2006 on 09/17/06 at 15:04:15, Graham Ellis wrote:
'cuz I put it in the wrong place ![]() OK now cheers - Ted This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |