1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Extracting data from a flat file & displaying on website

Discussion in 'Perl' started by dark_stranger, Nov 29, 2007.

  1. dark_stranger

    dark_stranger New Member

    Joined:
    Nov 29, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I am using a shopping cart called PPCal (shoppingcart.org) that is perl/cgi based and uses a flat file database. It comes with its own shop front, but also you can intergrate its add to cart & view cart buttons into your site, but I also want to get other stuff displayed such as total items per catorgory or if the item is sold. Does anyone know if its possible & if so, how?
    Thanks in advance.
     
  2. naveen

    naveen New Member

    Joined:
    Jun 2, 2005
    Messages:
    39
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Calcutta, India
    Home Page:
    I've not worked with the shopping cart you've mentioned, so I won't be able to suggest you a solution straight away. However, going by the details you've provided (which are very inadequate to give a solution!) it seems that what you want, is possible. However, you have to post more specific questions along with the relevant code if anyone is to help you out in forums. Try to understand the working of the shopping cart application and the structure in which the data is stored in the flat files. And then post the relevant parts which can then be analysed by the experts here to help you. I don't think anyone who has not worked with that particular app can devote the time required to analyse the app for you.

    So you've got to give the leads for us to work on your issue.
     
  3. dark_stranger

    dark_stranger New Member

    Joined:
    Nov 29, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi, thanks for replying and hopefully I have the info you need, although there maybe a better code that will be more suitable for this problem like php. I am trying to get some php code or other code to count certain values in a text file and display them on a webpage. The text file is for a shopping cart and stores item details such as what catogory the item is in (1st coloum).

    1|halffrag|1|8001|9004|HalfFrag|10.00||1|||1|||||.00||.00|||1,
    2|FullFrag|1|8001|9005|FullFrag|10.00||1|||1|||||.00||.00|||1,
    3|DoubleFrag|1|8001|9006|DoubleFrag|10.00||1|||1|||||.00||.00|||1,
    4|Colony|1|8001|9007|Colony|10.00||1|||1|||||.00||.00|||1,
    1|Colony|1|8001|9007|Colony|10.00||1|||1|||||.00||.00|||1,

    One of my requirments is to display on my home page the number of items in a catogory. The value can be seen in the first coloum, therefore currently there is 1 item in each of the 4 catogories and 2 item in cat "1". Therefore is it possible to display on the front page the number of items in catogoy "1"? and then i can alter for 2, 3, 4, etc

    Therefore there are 2 items in catogory "1"

    Thanks in advance,
     
  4. dark_stranger

    dark_stranger New Member

    Joined:
    Nov 29, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    problem solved...
    PHP:
    <?php
        
    function get_item_count($file_path$category){
            
    $count 0;
            
    //open file
            
    $f fopen($file_path"r");
            
    //read next line
            
    while($line fgets($f)){
                
    //break up line into columns
                  
    $columns explode('|'$line);
                  
    //check for category value
                  
    if(trim($columns[0])==$category){
                    
    $count++;
                  }
            }
            
    //close file
            
    fclose($f);
            
    //return count
            
    return $count;
      }
      
      print(
    get_item_count('data.txt''2'));
    ?>
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    You have posted in the PERL forum and you solution seems to be in PHP. Is there something that is missing.
     
  6. dark_stranger

    dark_stranger New Member

    Joined:
    Nov 29, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    origianlly I thought it was a perl problem, but it evolved into a PHP problem & solution :eek:)
     

Share This Page