Getting variables from another file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ørjan Langbakk

    #1

    Getting variables from another file

    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?

    And what is the best way to get the informatin into the file that needs
    to parse it? $GET? or something else entirely?

    --
    mvh
    Ørjan Langbakk

    株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

  • Rik

    #2
    Re: Getting variables from another file

    Ø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.

    Grtz,
    --
    Rik Wasmus


    Comment

    • Ørjan Langbakk

      #3
      Re: Getting variables from another file

      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?

      --
      mvh
      Ørjan Langbakk

      株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

      Comment

      • Rik

        #4
        Re: Getting variables from another file

        Ø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.

        Grtz,
        --
        Rik Wasmus


        Comment

        • Ørjan Langbakk

          #5
          Re: Getting variables from another file

          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
          >>>productnam e 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
          >>periodicall y upload a changed csv easily. Maybe even
          >>parse_ini_fil e() 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="produc t1"
          ???


          --
          mvh
          Ørjan Langbakk

          株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

          Comment

          • Gary Hasler

            #6
            Re: Getting variables from another file

            But why not create a seperate csv (if you really want it seperate) if you're
            already using it's capabilities?
            ...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.
            I agree totally. I store a list of about 40 unit rate prices for our online
            quote system as a very small .csv file, and our cost estimating staff can easily
            load it in Microsoft Excel and play with it all they want without having to get
            into databases at all. When they're finished, I upload it to the server easy as
            pie.

            Comment

            • mootmail-googlegroups@yahoo.com

              #7
              Re: Getting variables from another file


              Ørjan Langbakk wrote:
              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,
              )
              ?>
              >
              To do this, put that $prices array in a file all by itself.
              Then, from the page that needs to use this data, use require_once [1]
              to include the file.
              To access the data for a specific product, then, you would say, for
              example, $prices['product1'].

              This can be a very easy to implement solution, but difficult to
              maintain in the long run. I agree with those advocating using, at the
              very least, CSV (though I've never done it, so probably won't be of
              much help). Once someone decides they want to do more with the website
              and/or the data, you are going to wish you had a more flexible data
              backend than an include file with an array.


              [1] - http://us2.php.net/manual/en/function.require-once.php

              Comment

              • Ørjan Langbakk

                #8
                Re: Getting variables from another file

                Den 14.08.2006 22:23, skriblet Gary Hasler følgende:
                >But why not create a seperate csv (if you really want it seperate) if you're
                >already using it's capabilities?
                >
                >...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.
                >
                I agree totally. I store a list of about 40 unit rate prices for our online
                quote system as a very small .csv file, and our cost estimating staff can easily
                load it in Microsoft Excel and play with it all they want without having to get
                into databases at all. When they're finished, I upload it to the server easy as
                pie.
                Well... I use TextPad for my webcoding, and has no problems using that
                with custom highlights for CSV :)

                But still, I kinda don't understand how I would extract only ONE value
                for each row in the CSV file, into the other file. If someone can point
                me in the right direction for something like that, it would be great -
                the lesser the files to maintain, the better.


                --
                mvh
                Ørjan Langbakk

                株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

                Comment

                • Ørjan Langbakk

                  #9
                  Re: Getting variables from another file

                  Den 14.08.2006 22:41, skriblet mootmail-googlegroups@ya hoo.com følgende:
                  Ørjan Langbakk wrote:
                  >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,
                  >)
                  >?>
                  >>
                  >
                  To do this, put that $prices array in a file all by itself.
                  Then, from the page that needs to use this data, use require_once [1]
                  to include the file.
                  To access the data for a specific product, then, you would say, for
                  example, $prices['product1'].
                  Wouldn't that mean that it would have to read through the entire
                  prices.php file, to get the one value I need? I mean, using require_once.

                  Wouldn't it be possible to just use the $_GET variable or something,
                  using the prices.php as the file from where to get the data?

                  Or is the require_once the best way of doing this?

                  --
                  mvh
                  Ørjan Langbakk

                  株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

                  Comment

                  • Ørjan Langbakk

                    #10
                    Re: Getting variables from another file

                    Den 14.08.2006 22:41, skriblet mootmail-googlegroups@ya hoo.com følgende:
                    Ørjan Langbakk wrote:
                    >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,
                    >)
                    >?>
                    >>
                    >
                    To do this, put that $prices array in a file all by itself.
                    Then, from the page that needs to use this data, use require_once [1]
                    to include the file.
                    To access the data for a specific product, then, you would say, for
                    example, $prices['product1'].
                    >
                    This can be a very easy to implement solution, but difficult to
                    maintain in the long run. I agree with those advocating using, at the
                    very least, CSV (though I've never done it, so probably won't be of
                    much help). Once someone decides they want to do more with the website
                    and/or the data, you are going to wish you had a more flexible data
                    backend than an include file with an array.
                    >
                    >
                    [1] - http://us2.php.net/manual/en/function.require-once.php
                    Hm. Well, I got it to work, but not as I wanted to. Okey, the file
                    prices.php and the require_once all work fine, but since I already
                    include a CSV-file with all the specific details about each product, I
                    need the <?php echo $prices['product1']; ?to be _in_ the CSV file I
                    parse - and THAT seems to be a problem, since the code just shows up in
                    the page source code, it's not being parsed, and I wonder how I can
                    correct this?

                    --
                    mvh
                    Ørjan Langbakk

                    株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Getting variables from another file

                      Ørjan Langbakk wrote:
                      Den 14.08.2006 22:23, skriblet Gary Hasler følgende:
                      >
                      >>But why not create a seperate csv (if you really want it seperate) if
                      >>you're
                      >>already using it's capabilities?
                      >>
                      >>
                      >>...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.
                      >>
                      >>
                      >I agree totally. I store a list of about 40 unit rate prices for our
                      >online
                      >quote system as a very small .csv file, and our cost estimating staff
                      >can easily
                      >load it in Microsoft Excel and play with it all they want without
                      >having to get
                      >into databases at all. When they're finished, I upload it to the
                      >server easy as
                      >pie.
                      >
                      >
                      Well... I use TextPad for my webcoding, and has no problems using that
                      with custom highlights for CSV :)
                      >
                      But still, I kinda don't understand how I would extract only ONE value
                      for each row in the CSV file, into the other file. If someone can point
                      me in the right direction for something like that, it would be great -
                      the lesser the files to maintain, the better.
                      >
                      >
                      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.

                      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).

                      But OTOH, if you've got that much data you really need a database
                      anyway, so I'm assuming the amount of data is limited. In that case
                      either way should not be that much of a performance problem.


                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Ørjan Langbakk

                        #12
                        Re: Getting variables from another file

                        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.

                        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.

                        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.
                        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.

                        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.

                        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.

                        Is there a way, or some tips as to what to look for, when it comes to
                        parsing php-code in CSV-files?

                        --
                        mvh
                        Ørjan Langbakk

                        株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

                        Comment

                        • Jerry Stuckle

                          #13
                          Re: Getting variables from another file

                          Ø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().

                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstucklex@attgl obal.net
                          =============== ===

                          Comment

                          • Ørjan Langbakk

                            #14
                            Re: Getting variables from another file

                            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

                            株式会社キュービックでは「店舗・オフィス」を中心に、デザイン・マテリアル・カラー・ライティング・フォルムを創造・融合し、あらゆる都市空間のニーズにあった設計・施工を目指します。

                            Comment

                            Working...