#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    Hi,

    I am new to php and I am looking for a flat file database system which will allow me to call different product prices from the flat file database. So basically I have a page that lists many different products. For each product I want to list the price. So I would do a search for each individual product code and then return the appropriate price. Can this be done? And can someone point me in the right direction because I don't even know where to start. I first tried doing this using cgi and some ssi's. However due to multiple ssi's on one page (for mutiple prices) it was too slow and so I was recommended to use php. I would be very grateful to someone who can help me. Please note, the only functionality i really need is for the text file to be searched on and to be able to return a price or code value. Thanks in advance.

    Dave.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    It would be really much easier to help you if I knew the format of your "flat file database". If this really is a text file rather than a real database I would suggest you'd move on to mysql or similar if you only can. And if you can't paste some records from that file so we can help you.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    Ok, well I can't really move to mySql for lack of support. However i can use any delimeted type database (eg , or ; or | etc). The fields would be like...
    Product_Code, Product, Price, Supplier. I want to be able to search on the product code and display the price. Do you think this is possible??? Thanks heaps for your help.

    Dave
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    I am also not sure what other databases I can use but I am open to suggestions (but not solutions such as msql, mysql etc as I believe they are not supported on my server and that they would be overkill anyway). I am not sure if DBM would be a suitable type solution but I am still unsure how to implement a system using this as well. Thanks again.

    Dave
  8. #5
  9. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2000
    Posts
    1,058
    Rep Power
    22
    I'm also new to PHP, but have had some
    success using flat files. You might want
    to give something like this a try:

    <?php
    $fileName = "yourDataFile"; //The flat file
    //name goes here
    $myFile = fopen("$fileName","r");
    if(!($myFile)) {
    print("Couldn't read $fileNamen");
    }
    while(!feof($myFile)) {
    $myLine = chop(fgets($myFile, 255));

    //Use as many $var's as you have fields.
    //Also, this example is 'pipe' delimited.
    list( $var1, $var2 )=split("[|]", $myFile);


    //Put your evaluation code here...
    //ie. if($var == what I'm looking for) {
    // print("some HTML");
    // }

    }
    fclose($myFile);
    ?>

    Hope this helps.
    Like I said though, I'm new to PHP so this
    may not be the most efficent code...

    Scott
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    I tried this code but couldn't get it working Does this code allow me to use multiple search type items on the one page? I need at least say 20 or so. I was thinking the top part where it opens the file could be at the top, say in the head tag. Then whenever I need to pull in code use the find and print bit. Would that work? Also, are you able to send me an example page you have used as I tried the one you sent and couldn't get it working. Thanks for your help.

    Dave
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    Ok, well I have something finally working due to some help from WDN. However because I want to seek multiple items on the one page I want them to be displayed in the order that I want them, not the order that they appear in the database. However I am having trouble using the rewind command. I cannot get it to work properly. Here is what I have so far. Can someone please suggest where to put the code to rewind to the start of the file so that I get the results in the order that I seek for them. Thanks in advance...

    -------------------
    <?php
    $myFile = fopen("hardware.txt","r");
    while(!feof($myFile)) {
    $myLine = chop(fgets($myFile, 255));
    list( $code, $product, $price, $street, $supplier ) = split("[|]", $myLine);
    ?>

    </head>

    <p>

    <?php

    if($code=="GREEN12") {
    print("<font size='2' face='Arial, Helvetica'>");
    print("Code: <b>$code</b><br>n");
    print("Street Price: $<b>$street</b><br></font>n");
    }

    if($code=="TURBO02") {
    print("<font size='2' face='Arial, Helvetica'>");
    print("Code: <b>$code</b><br>n");
    print("Street Price: $<b>$street</b><br></font>n");
    }
    if($code=="GREEN05") {
    print("<font size='2' face='Arial, Helvetica'>");
    print("Code: <b>$code</b><br>n");
    print("Street Price: $<b>$street</b><br></font>n");
    }
    ?>

    <?php
    }
    fclose($myFile);

    ?>
  14. #8
  15. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2000
    Posts
    1,058
    Rep Power
    22
    I see a potential problem with your code,
    and have a suggestion as well.

    First, the problem.
    You're adding a </head> and <p> tag every
    time you go through the loop. That could
    result in some rather odd looking output.

    Now, the suggestion.
    You can check for multiple matches in one
    "if".

    if($code=="GREEN12" &#0124; &#0124; $code=="TURBO02") {
    print("some HTML..."n);
    }

    You can get some pretty complex evaluations
    just using &#0124; &#0124; and && (or and and).


    As for using the rewind function, I've never
    had a use it (in the week or so I've been
    thrashing about with PHP )

    Good Luck,
    Scott
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    well the idea was to have this code inside my existing page. So i would have a beginning <head> tag etc. Also it wouldn't be going through a loop. It would only go through once. Perhaps if I show you a page that will demonstrate how I want to lay it out. This page I was able to link the prices using cgi but you will notice it is very slow to load. The cgi brings in the prices that are in bold. I merely call the code of the product I want and make it return the price. This is the same type of thing i want to do with my php. Here is the page... http://www.microway.com.au/catalog/listcpp_addons1.stm

    As for the suggestion about using the | and & I don't think it would help me much as i will know which product to call in so I just will search on that and return the price. And I will want several, each below its respective description.

    thanks again.

    dave

Similar Threads

  1. Pointer problem in opening a file
    By LAKI in forum C Programming
    Replies: 13
    Last Post: February 11th, 2004, 09:27 AM
  2. Reading from a database file to an ArrayList
    By rbutturini in forum .Net Development
    Replies: 0
    Last Post: February 7th, 2004, 12:53 AM
  3. PHP file upload script trouble
    By casbboy in forum PHP Development
    Replies: 9
    Last Post: February 5th, 2004, 08:42 PM
  4. New Line in Flat file
    By clojita in forum PHP Development
    Replies: 2
    Last Post: February 1st, 2004, 10:21 AM
  5. Inserting text into textarea box from flat file
    By GWalnum in forum PHP Development
    Replies: 2
    Last Post: January 28th, 2004, 12:45 PM

IMN logo majestic logo threadwatch logo seochat tools logo