On 13 Mar 01, at 9:43, Robert V. Zwink wrote:

> http://phpclasses.upperdesign.com/browse.html/package/52

Thanks for this. Very simple and straightforward, but I don't see 
much in there that helps me.

> The above link will take you to a class to manipulate CSV files. 
> This might help you understand file access in php.  If you want to
> maintain a database within a text file using CSV file format may
> help. 

There is not (and will never be) any editing of this text file on the 
website. It's simply read-only, a periodically uploaded catalog of 
selected items to allow website viewers to search selected inventory 
on this client's website: <http://www.wurlitzerbruck.com/>.

> If you have specific questions don't hesitate to post.

[Keep in mind that I'm an experienced Visual Basic programmer but 
I've never done very much file I/O and I'm a complete newbie to PHP 
with no PERL experience, either]

I can open the file with fgetcsv(), and there it all is in an array, 
which is very nice. However, what I really want is to pull only rows 
matching certain criteria into an array and then display *those*. 
I've created the data output as a flat file, with the many-to-one 
data flattened into single fields.

[am I correct in surmising that the array created by fgetcsv() is 
addressable only by index number, and not by column name?]

I need to match on:

   CreatorID
      (one per row, exact match)
   CreatorCategories
      (multiple items per row, match multiple partial strings)
   KeyWords
      (multiple items per row, match partial string)
   Title
      (one per row, partial match against a concatenation of
      three columns)

The WHERE clause from my ODBC SQL strings would run like this:

   WHERE (CreatorID IN (232,654,1034)) 
     AND (CreatorCategories Like '%Composer%' OR 
          CreatorCategories Like '%Pianist%') 
     AND (KeyWords Like '%Ballet%' OR 
          KeyWords Like '%Cantatas%' OR 
          KeyWords Like '%Chamber Music%')
     AND ((BibHeader & AutoHeader & OtherHeader) Like 'Sonata%')

(the example makes no sense, of course, but includes all the 
possibilities).

Now, obviously, I need a regular expression to compare a field value 
to a list of values, and another to see if any of a list of values is 
a substring of the field value.

Regular expressions always make my eyes glaze over, but these are so 
simple (aren't they?) that I can't see any examples that I can 
understand are applicable to what I want -- the examples all seem 
designed to help you with more complicated tasks than what I need.

And, obviously, I want to return just the rows that have a match.

If I have the whole file in an array (with fgetcsv()), the row number 
of the array should be all I need to return, and then I can copy that 
whole row into a second array.

What I'd really like is a way that would selectively copy to an array 
rather than copying from one big array to a smaller array, but the 
file has to be open, in memory, either way, right? Or can one read it 
in one line at a time, test against the conditions, and copy to the 
array or move on depending on the match?

Once the selected rows are in an array, I'm set, since that's a piece 
of cake.

I've read the f functions and the preg and ereg functions, but I'm 
stuck on:

1. don't know what strategy is best for opening the file.

2. don't know how to construct the needed regular expressions.

3. don't know how to find something in the file with the regex and 
return a line number (or array number if it's in an array), and then 
get that line into the array I really want (or just display the 
results at that point?).

Actually, it makes a great deal of sense to fgetcsv() the file, then 
walk through it testing each row, and outputting only the matches. 
However, that won't be sorted, so I'd really need to copy the matches 
into an array where they can be sorted, since the output needs to be 
sorted. And, of course, in the end, I'll want to deliver results in 
blocks of 20 per page or so (but I think that can be dealt with by 
passing a row identifier and the array on to the next page to 
display; not that I know how to do that, but I can figure it out).

Geez. It sounds pretty complicated, after all.

Thanks in advance for any help/pointers any of you are able to give.

-- 
David W. Fenton                         |        http://www.bway.net/~dfenton
David Fenton Associates                 |        http://www.bway.net/~dfassoc

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to