|
Posted by rjan Langbakk on 08/17/06 18:24
Den 15.08.2006 13:38, skriblet Jerry Stuckle følgende:
> Ørjan Langbakk wrote:
>> Den 15.08.2006 04:22, skriblet Jerry Stuckle følgende:
>>
>>> You're going to want to extract at least 2 values - the item number
>>> and the price. Otherwise, what happens if, for instance, the first
>>> line got deleted? You might be selling a $75,000 Jaguar for $0.75.
>>
>> Nope. I'll want to extract ONE value :)
>>
>> You see, the CSV-file in question is the basis for the product
>> categories - if something gets deleted, it will show up pretty soon on
>> the screen, so to speak - not to forget that using XHTML 1.0 Strict, any
>> parsing error will make the page break - which in turn of course will
>> show that there is an error. So, how do I, simply, extract everything
>> that is placed behind the _last_ comma in a CSV-file? As the price
>> itself isn't a set size (it varies from several prices, to only one, so
>> the length is fairly unpredictable). I will want to make this possible
>> to extract into several files.
>>
>
> Very dangerous. And sooner or later it will fail. But you'll have to
> explain it to the boss/customer, not me.
>
>> As it is now, I have one page detailing each of the product categories.
>> These pages loads the appropriate CSV-file, and lists it's values as a
>> table.
>>
>
> OK, no problem there.
>
>> Now, in the CSV-files, I've got everything from 6 to 60 products - maybe
>> more as the time goes by. What I need to do is something like extract
>> the value that is stored in the last field (after the last comma) into
>> several files.
>>
>
> If you keep it in a csv file, you'll have read the entire file and parse
> each line. You can't get just "everything after the last comma". But
> for 60 items this would be minimal time.
>
>>> Using require_once is easy - but it means you have to parse the entire
>>> file. If it's long, that might be a problem. A csv file requires you
>>> to parse every line until you get to the one you want (unless you have
>>> fixed length blocks of data, random access will not work).
>>
>> Well. I tried the require_once suggestion, and ran into trouble as the
>> price I'm trying to parse, is set into the CSV-file where I get the rest
>> of my data. For some reason the php-code I put in the appropriate field
>> in the CSV won't parse. I'm thinking maybe it's a quote-error somewhere,
>> or maybe it's in the way I parse the CSV into the html-file. I don't know.
>>
>
> No, you won't be able to do it in a .CSV file. If the extension isn't
> .php (or others, as your webserver may have set up), the server won't
> parse the PHP code. And the rest will be output as text.
>
> To use require_once, you'll have to build a file with PHP code as
> mootmail indicated.
>
>> And, besides, I still need to get ONLY the value from the price-field
>> into the singelpage product descriptions. Which I have NO clue as to how
>> to do with CSV.
>>
>
> Check out fgetcsv().
>
>> The best way would be to just have a single file with all the prices,
>> and call up an arrayparameter in BOTH the CSV-file and the singlepage
>> product description - but as I already said, the php-code in the
>> CSV-file doesn't parse. It just sits in the source code when I'm looking
>> into it - which tells med that the server doesn't see it as php at all,
>> but as pure tekst, or something - it's not visible, so I'm guessing it
>> interprets it at comments or something.
>>
>
> And as I explained, it won't.
>
>> Is there a way, or some tips as to what to look for, when it comes to
>> parsing php-code in CSV-files?
>>
>
> Read up on fgetcsv().
I will. At least I now know that there is no way to make the PHP-code
work from inside the parsed CSV-file - thereby making that more or less
a moot point.
--
mvh
Ørjan Langbakk
http://www.bergenpchjelp.no
http://www.cubic-design.net
[Back to original message]
|