Thread: Please help!!!

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

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    hi,

    I am currently trying to open a text file. I then have a function that will search for an item that i specify in my .php3 file and it goes through the function and returns the price. However I am getting an error and it seems that the initial opening of the text file is not carrying through to the function. Can someone please help... here is my code and the error I am getting:

    Code:
    <script language="php">
    $myFile = fopen("hardware.txt","r");

    function getPrice($searchParam) {

    // $myFile = fopen("hardware.txt","r");
    // when i include this line the erro goes away, however performance is also decreased dramatically. page becomes very slow to load.
    while(!feof($myFile)) {
    $myLine = fgets($myFile, 255);
    list( $code, $product, $price, $street, $supplier ) = split("[|]", $myLine);
    if($code == $searchParam) {
    echo "$pricen";
    }
    }
    return("Call!");
    }
    </script>

    some info in here...

    <script language="php">
    getPrice('TURBO02');
    print ("<BR>");
    </script>

    more info in here...

    <script language="php">
    fclose($myFile);
    </script>

    Error:
    Warning: Unable to find file identifier 0 in /import/clients/m/microway/www.microway.com.au/htdocs/catalog/list_comm.php3 on line 17

    Line 17 happens to be this:
    while(!feof($myFile)) {

    Please help!!! Thanks in advance!

    Dave
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    If you open the file outside of the function but want to manipulate the file in the function you'll have to pass the file id as a parameter of the function or declare it global. Otherwise it won't be available to the function.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    sorry for my ignorance but im just new to php... could you possible show me how I would define it globally??
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    Try:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $fd=1;
    function function_name () {
    print isset($fd); // Local variable.. Not defined.
    global $fd;
    print isset($fd); // Global variable.. defined on line 1
    }
    function_name();
    [/code]
    ---
    Dist - dist@clan-station.org - Founding member of Clan Station

    [This message has been edited by Dist (edited April 18, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo