Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Need some help with a simple script.

    Hi there, i am new to php and havent spent 2 long learning it. I know how to read and write files using perl/cgi but arent accustomed to the language of php. I was wondering if anyone had a easy way to open a file, search for values and either update them or print them to screen?

    ie i want to make a .txt file with a list of pictures . and comments and descriptions located adjacent. ie

    photo 1 - comment='How stupid do i look', description='on holidays'\n
    photo 2 - comment='blah' ... etc etc
    photo 3

    so when i enter a new description or comment it will find the corresponding picture and update the fields....

    and ideas. Just a push in the right direction would be stella.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I would recommend you use a database such as MySQL rather than a file. If you don't have access to a database or just don't want to use one, then I would recommend you use a comma-delimited file to store the information.

    You can use the fputcsv() function to write a record to the file, and the delimiters will be handled automatically. Use fgetcsv() to read the file.

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok ive used fputcsv but am having trouble getting the entire line to be replaced with the value. It keeps replacing the line below it?
    THe code is really messy. any ideas?

    PHP Code:
    <?php 
    $mytival 
    "";

                if(
    $action == "attachme") {
                
    $mytival "$comdesc";
                
    $stsearch "$imname";
                
    $list = array ("$stsearch,$mytival");                        
                                                    
                            
                            
    $row 1;
    $done false;
    $fp fopen("commentstore.csv""r+");
    while ((
    $data fgetcsv($fp",")) !== FALSE) {
       
    $num count($data);
       
    $row++;
       for (
    $c=0$c $num$c++) {
           
    $settext $data[$c];
         
           if (
    $settext == $stsearch){   // it seems to be stuffing up in this if statement?
           
                   
    foreach ($list as $line){                            fputcsv($fpsplit(","$line));
                         
    $done true;
                        }
                         break;
                            
                             

                }            

                               
       }
    }
    if (
    $done == false){
        
    fclose($fp);
        
    $list = array ("$stsearch,$mytival");
        
    $fp fopen("commentstore.csv""a+");
        foreach (
    $list as $line) {
      
    fputcsv($fpsplit(","$line));
      }
    fclose($fp);    
                            }
                    
                                                
                        }
                        
                        
                        
                    
        
        
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •