Extracting data from a flat file & displaying on website

dark_stranger's Avatar, Join Date: Nov 2007
Newbie Member
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.
0
naveen's Avatar
Go4Expert Member
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.
0
dark_stranger's Avatar, Join Date: Nov 2007
Newbie Member
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,
0
dark_stranger's Avatar, Join Date: Nov 2007
Newbie Member
problem solved...
PHP Code:
<?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'));
?>
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You have posted in the PERL forum and you solution seems to be in PHP. Is there something that is missing.
0
dark_stranger's Avatar, Join Date: Nov 2007
Newbie Member
origianlly I thought it was a perl problem, but it evolved into a PHP problem & solution )