|
Posted by rjan Langbakk on 12/17/78 11:55
Den 14.08.2006 17:59, skriblet Rik følgende:
> Ørjan Langbakk wrote:
>> Den 14.08.2006 16:21, skriblet Rik følgende:
>>> Ørjan Langbakk wrote:
>>>> I wanna make a file that holds the complete pricelist for a small
>>>> webshop (yes, I know that a database in the background would be a
>>>> lot simpler, but that is not an option today, unfortunately).
>>>>
>>>> I'm thinking something like creating a file that holds the
>>>> productname and the price, and then just get the price from the
>>>> other pages that needs it. (Typically an overview page of all the
>>>> products in a
>>>> category, and the spesific product pages).
>>>>
>>>> I'm thinking it would be possible to create something like:
>>>>
>>>> #Product 1
>>>> $produkt1 = 2000
>>>> #produkt 2
>>>> $produkt2 = 1400
>>>>
>>>> and so on
>>>>
>>>> Is this a good way to create this?
>>> Why not create an CSV, and use fgetcsv() and fputcsv() to get/store
>>> the data? That way it's still pretty easy to update/add/delete
>>> stuff, and you could even run a database somewhere else that would
>>> periodically upload a changed csv easily. Maybe even
>>> parse_ini_file() could help you here, but I doubt it will handle
>>> very nicely once the shop grows.
>> Well... I already have CSV-files of all the product-listing pages. But
>> what I want is _one_ file just holding the prices, basically - no
>> other info. The reason for this is that the prices change frequently
>> (sales, campaigns etc.) - therefore it would be much easier to just
>> store each price as a variable, and then get that variable on the
>> pages that need
>> the price displayed.
>>
>> So, I think maybe my original suggestion is better, if it works - will
>> it work?
>
> It can work perfectly.
> I'd prefer an array though: using a product id, and an include like:
>
> <?php
> $prices = array(
> 1 => 1200,
> 2 => 4200,
> etc...
> )
> ?>
>
> But why not create a seperate csv (if you really want it seperate) if you're
> already using it's capabilities?
>
> 1,1200
> 2,1400
> etc...
>
> It seems more logical/maintainable to me. It seems even more logical to me
> to keep the price in the original CSV, and to maintain it there. It's not
> that hard to write a framework than can manipulate a csv as easily as a flat
> table.
Maybe? I'm not that capable at PHP (at least not yet) - What I wonder is
how I would take JUST that value (ie. the price) from the CSV-file I
already have?
Could I use a kind of one-liner to just put in the last group in the CSV
(the price is always last)?
And, as I am also new to the array-functions, how would I go around
creating that file, and pulling the different values from it?
I'm thinking I could use something like:
<?php
$prices = array (
product1 => 1200,
product2 => 2400,
product3 => 3450,
)
?>
Would this work? Does the names have anything to say? And, to pull one
value from this file - how would I do that? Assuming that this is put in
a separate PHP-file, that is. Like eg. prices.php
Would I use something like <?php $_GET["prices.php"] $prices="product1"
?> ??
--
mvh
Ørjan Langbakk
http://www.bergenpchjelp.no
http://www.cubic-design.net
Navigation:
[Reply to this message]
|