You are here:  » Filtering $records before inserting into SQL


Filtering $records before inserting into SQL

Submitted by jmeier on Mon, 2008-09-01 14:40 in

Well, I have my script working perfectly thanks to the great tool and excellent support. Now I want to make an adjustment so I only add relevant records into mysql based on the value(s) in one of the xml fields. I have an xml field in the $records called TOURNAMENT-NAME. I would like to filter this based on name = "PGAX_*"(starting with the characters PGAX_ and having any characters after that. These are the only records I want to insert into sql or return from my records function. Hopefully I explained this logically. Is this possible? And if so how? Thanks

Jim

Submitted by support on Mon, 2008-09-01 14:59

Hello Jim,

Something like this should do the trick - at the top of your myRecordHandler() function:

  if (strpos($record["TOURNAMENT-NAME"],"PGAX_")!==0) return;

strpos returns the position of the substring if found - including 0 (zero) if the string is found starting at position zero, which is what you are looking for in this instance. However, it also returns boolean FALSE if the string is not found, so we have to use one of PHP's "absolutely equal to" comparison operators, !== (not absolutely equal to) in this case which compare type and value to test for a return value that is not 0, meaning that you are not interested in this record and therefore "return"ing from the function without doing anything...

Hope this helps!
Cheers,
David.