A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Need a little help with PHP please Array

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Location
    U.K
    Posts
    23

    Post Need a little help with PHP please Array

    I have this script which receives the posted variables and strings them all together in the way I want into $ResultsArray. Perfect

    When I use the foreach loop and echo the array it works. Perfect

    When I send another lot of the posted variables again and string them all together into $ResultsArray it overwrites the first value so instead of

    So instead of getting eg.

    0: rubbish
    1: garbage

    I get:

    0:garbage

    because it has overwritten rubbish.

    PHP Code:
    <?PHP

            $AuthorBox 
    $_POST['AuthorBox'];
            
    $TitleBox $_POST['TitleBox'];
            
    $TitleBox ="<i>$TitleBox</i>";
            
    $YopBox $_POST['YopBox'];
            
    $PopBox $_POST['PopBox'];
            
    $PublisherBox $_POST['PublisherBox'];
            
    $EditionBox $_POST['EditionBox'];
            
            
     
    $ResultsArray[$value] = $AuthorBox.'. ('.$YopBox.'), '.$TitleBox.', ('.$EditionBox.' edition), '.$PopBox.': '.$PublisherBox.'.<BR><BR>';
            
            foreach (
    $ResultsArray as $key => $value) {
        echo (
    "$key$value<br>\n");
        
    };
            
            
            
            


            
    ?>
    Any thoughts on how to solve this would be very awesome.

    Thanks

    Bottlebank

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Location
    U.K
    Posts
    23
    Sorry copied the wrong PHP, this one is the one....almost the same bar the $value in the array key

    PHP Code:
    <?PHP

            $AuthorBox 
    $_POST['AuthorBox'];
            
    $TitleBox $_POST['TitleBox'];
            
    $TitleBox ="<i>$TitleBox</i>";
            
    $YopBox $_POST['YopBox'];
            
    $PopBox $_POST['PopBox'];
            
    $PublisherBox $_POST['PublisherBox'];
            
    $EditionBox $_POST['EditionBox'];
            
            
     
    $ResultsArray[] = $AuthorBox.'. ('.$YopBox.'), '.$TitleBox.', ('.$EditionBox.' edition), '.$PopBox.': '.$PublisherBox.'.<BR><BR>';
            
            foreach (
    $ResultsArray as $key => $value) {
        echo (
    "$key$value<br>\n");
        
    };
            
            
            
            


            
    ?>

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    well, you have flash send data to some php, and the php gets them, adds them to a new array, and quits.
    The next data from flash will start a new php script and do the same.

    In order to actually accumulate data, the php script would need to save the data to some file or database, and then the next run could add to the saved data and return all results.
    If using a file, you would perhaps use
    Code:
    $fp = fopen("datafile.txt", "a");
    fputs($fp, $AuthorBox.'. ('.$YopBox.'), '.$TitleBox.', ('.$EditionBox.' edition), '.$PopBox.': '.$PublisherBox."\n");
    fclose($fp);
    $fp = fopen("datafile.txt", "r");
    while($line = fgets($fp))
          echo($line);
    fclose($fp);
    This is not perfect, but I assume there will never be two simultaneous submissions in your setup

    Musicman
    Last edited by Musicman; 02-09-2012 at 12:39 PM.

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Location
    U.K
    Posts
    23
    So....

    $fp = fopen("datafile.txt", "a");
    fputs($fp, $AuthorBox.'. ('.$YopBox.'), '.$TitleBox.', ('.$EditionBox.' edition), '.$PopBox.': '.$PublisherBox."\n");
    fclose($fp);
    $fp = fopen("datafile.txt", "a");
    while($line = fgets($fp))
    echo($line);
    fclose($fp);
    by doing this my variables will be saved to a text document and then opened again by the php script.

    On the second time of sending the variables, won't it over write what is already on the .txt file?

    Bottlebank

  5. #5
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    that's the "a" (append) argument to fopen - note I corrected a typo and changed the second fopen to use "r" for reading

    Musicman

  6. #6
    Junior Member
    Join Date
    Jan 2012
    Location
    U.K
    Posts
    23
    Music Man, That works a treat.

    Many thanks Mate, I owe you a cyber pint!

    Bottlebank

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center