A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Flash and PHP Help

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    Flash and PHP Help

    Hi All ok so I have a PHP file that Displays the 20 most recent posts in HTML form, now I wanna Send this Info to Flash Dymanic TXT box

    PHP Code:
    <?php

    error_reporting
    (E_ALL);
    ini_set('display_errors''on');
    $db sqlite_open("MyDATABASEHERE.db"0666$sqliteerror)
       or die(
    $sqliteerror);
    //echo "<p>Recent Posts</p>";
    $sql "SELECT * FROM phpbb_posts ORDER BY post_time DESC LIMIT 16";
    //echo "<p>Query: " . $sql . "</p>";
    $recent sqlite_query($db$sql)
       or die(
    sqlite_error_string(sqlite_last_error()));


    while (
    $recent_row sqlite_fetch_array($recentSQLITE_ASSOC))
    {
            
        
    // get data
        
    $post_id $recent_row['post_id'];
        
    $topic_id $recent_row['topic_id'];
        
    $forum_id $recent_row['forum_id'];    
        
    $poster_id $recent_row['poster_id'];
        
    $post_time $recent_row['post_time'];

        
    // get topic name
        
    $topic_name sqlite_query($db"SELECT topic_title FROM phpbb_topics WHERE topic_id='$topic_id'");
        
    $topic_name sqlite_fetch_array($topic_name);
        
    $topic_name $topic_name['topic_title'];
        
        
    // get username 
        
    $username sqlite_query($db"SELECT username FROM phpbb_users WHERE user_id='$poster_id'");
        
    $username sqlite_fetch_array($username);
        
    $username $username['username'];
        
        
    //var for flash txt box is "toflash"
        
        
    $Passtoflash "$username posed in $topic_name<br />";

        echo 
    "&toflash=$Passtoflash";
        

    }

    ?>
    but if i Add the "&" thing to this line echo "&toflash=$Passtoflash";
    Flash reads only the very last post

    If I remove the "&" thing from the line Flash Reads all data
    but from the second row it adds toflash= to every line thereafter

    This is what is returned in flash TXT box

    EG:
    Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name

    and so on

    How do i get rid of toflash= ???
    only First line reads correct

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    can you add all your data to a var in the loop.. and then pass it all at once after to the Flash?

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    Maybe, but i have no idea how to do that, I'm very new to PHP and this PHP file took me over a week to figure out...

    Do you maybe have some samples that could work ?

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    yeah my PHP and mySQL skill as weak (at best) LOL..

    and usually when I send stuff back from PHP.. I send it back as XML as well..

    like this..

    (notice how the ECHO is outside of the loop)

    $xml_output = "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<clients>\n";
    for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
    $row = mysql_fetch_assoc($result);
    $xml_output .= "\t<client id='" . $row['id'] . "'>" . $row['office_name'] . "</client>\n";
    }
    $xml_output .= "</clients>";
    echo $xml_output;
    are you using a sendAndLoad() method from flash?

    are you send any data to PHP first?


    so maybe try:

    moving this:
    echo "&toflash=$Passtoflash";

    to outside the loop?

    I would also 'add' to the var instead of overwriting it each time.

    $Passtoflash . = "$username posed in $topic_name<br />";


    see what kind of results you get.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    OK Moved echo "&toflash=$Passtoflash"; outside of while loop Now only get 1 line No Others (most recent post from forums)

    are you using a sendAndLoad() method from flash?
    A: No just a Simple this.loadvariable(Doc.php); in flash
    with the text box is set to multiline, and HTML enabled
    Variable for text box is toflash, instance name None

    are you send any data to PHP first?
    A: No Not that i know ofl, Website is designed to Display (query) the PHP data on the main Page via only fetching it from SQlite nothing gets send back to it or the DB

    also If I modify this:
    Code:
    $Passtoflash . = "$username posed in $topic_name<br />";
    Nothing gets Displayed but if i remove the .(dot) I'm back to square 1
    BTW that is the . (dot) for on the above statement used for ?

    My Database is SQlite not MySQL if that helps and Thank You for Helping so far...

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    hi..

    lets see.. =)

    1.) maybe try using a more updated version of loadVariables()..

    try to using a LoadVar Object() instead

    (it lets you have much more control over what happens and when...etc..)

    example:
    actionscript Code:
    var myData:LoadVars = new LoadVars();
    myData.onLoad = function(success:Boolean) {
        if (success) {
        trace("THE DATA RETURNED: "+this.toString());
        } else {
        trace("Error loading/parsing LoadVars.");
        }
    };
    myData.load("Doc.php");


    2.) the " . " (dot) is to concatenate (add together) the data..

    so basically the loop was 'supposed' to keep adding the entries to the var..

    then you pass the whole var over..

    however in FLASH.. if you start every piece of data with the same 'var name' its only going to take the last one I believe ever..


    example:

    if flash gets this:

    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name

    what differentiates any of these?

    maybe try sending back some basic XML from the PHP script instead of text?

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    hey (me again)

    there shouldnt be a space between the . and the = should be .= I believe..

    probably why it wasnt working.

    $Passtoflash .= "$username posed in $topic_name<br />";

    I actually think your PHP and SQL stuff is 'fine'..

    its your approach..and the flash side of things.

    getting this:
    Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name
    toflash=Someone posed in Forum name


    would be normal the way you have it set up. =)

    since toflash is the var.. flash see it..and adds it to the text field.

    the other toflash vars are considers part of the data since..it has already found its var name toflash once..in the beginning.

    so you can either work on:

    a.) concatenating your data to 1 single var.. and 'then' pre-appending the toflash= flashVar in front...

    or

    b.) work on sending XML

    example:

    PHP Code:
    <?php

    error_reporting
    (E_ALL);
    ini_set('display_errors''on');
    $db sqlite_open("MyDATABASEHERE.db"0666$sqliteerror)
       or die(
    $sqliteerror);
    //echo "<p>Recent Posts</p>";
    $sql "SELECT * FROM phpbb_posts ORDER BY post_time DESC LIMIT 16";
    //echo "<p>Query: " . $sql . "</p>";
    $recent sqlite_query($db$sql)
       or die(
    sqlite_error_string(sqlite_last_error()));


    $Passtoflash "<?xml version=\"1.0\"?>\n";
    $Passtoflash .= "<posts>\n";


    while (
    $recent_row sqlite_fetch_array($recentSQLITE_ASSOC))
    {
            
        
    // get data
        
    $post_id $recent_row['post_id'];
        
    $topic_id $recent_row['topic_id'];
        
    $forum_id $recent_row['forum_id'];    
        
    $poster_id $recent_row['poster_id'];
        
    $post_time $recent_row['post_time'];

        
    // get topic name
        
    $topic_name sqlite_query($db"SELECT topic_title FROM phpbb_topics WHERE topic_id='$topic_id'");
        
    $topic_name sqlite_fetch_array($topic_name);
        
    $topic_name $topic_name['topic_title'];
        
        
    // get username
        
    $username sqlite_query($db"SELECT username FROM phpbb_users WHERE user_id='$poster_id'");
        
    $username sqlite_fetch_array($username);
        
    $username $username['username'];
        
        
    //var for flash txt box is "toflash"
        
    $Passtoflash .= "\t<post user='" $username " . " topic='" . $topic_name . "' />\n";

    }
    $Passtoflash .= "</posts>";
    echo 
    $Passtoflash;

    ?>

  8. #8
    Senior Member
    Join Date
    May 2010
    Posts
    178
    PHP Code:
    <?PHP
    $Passtoflash
    ="From Database ";
    $i=0;
    while(
    $i<10){
          echo 
    "&toflash$i=$Passtoflash$i&<br>";
         
    $i++;
    }
    echo 
    "&endOn=$i";
    ?>
    Just a simple experiment you can do to understand how PHP return to Flash with success.

    on flash:

    frame 1:

    Actionscript Code:
    loadVariables("http://localhost/whileLoopToFlash.php",_root);
    endOn=0;
    i=0;

    frame 2:

    Actionscript Code:
    if (endOn == "10") {   
        while (i<endOn) {
            trace(eval("toflash"+i));
            _root.i++;
        }
        gotoAndStop(1);
        trace(endOn);

    } else {
        play();

    }
    frame 3:

    Actionscript Code:
    gotoAndPlay(2);



    if this work you can get a clue to load chunk of data from PHP


    Poltuda

  9. #9
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    1.) IMHO.. using loadVariables() is NOT a recommended approach anymore.. using a loadvars object is. (as I posted an example)


    2.) You would have to 'know' the correct amount of 'entries' being returned in your method.. and how could you know that? You couldnt possibly know how many posts were made.. needs to be dynamic and be able to handle any amount of unknown returned posts.


    3.)why if you flash part 3 frames long? why is it longer than 1 frame...period?

    all the gotoAndPlayu() stuff isnt needed nor jumping back from frame to frame to check anything..

  10. #10
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Excuse ME, are you asking me, whispers for those answer?

    I have given an example on a very lite/old version of flash player, where loadVariables() can do the required need of banshee10000. So he/she can understand the basic to load the required data from PHP to Flash.

    Loading a chunk of data into flash from PHP is not an issue of loadVars() or loadVariables(), mySQL or SQlite. If your PHP can able to connect the database and can fetch the data from its table, it could be any database NO LIMIT.

    Now on the issue is to send maximum data of 20 entries.
    banshee10000 need to fetch the most recent post of 20 entries not more than that. So there is no question of dynamic limits of entries. PHP can handle as per the table structure, or by the date entries or by row, whatever it be.

    If he/she needs to allow users to load more than 20 entries with a next button, then simply use the "GET" or "POST" method to send data to PHP, which both LoadVars() and loadVariables() can able to handle.

    PHP Code:

    POST Method:

    PHP Code:
    $getNum $_POST["postNum"]; 
    OR

    GET Method:

    PHP Code:
    $getNum $_GET["postNum"]; 
    these are the code by which php can receive data.

    "postNum" is the variable name, which carries the number of entries to fetch.

    So, if you have a variable "postNum" in flash which holds the value to send to PHP, example: postNum=20; the "POST" or "GET" method is the method send it. Whereas PHP will only receive the value from "postNum" variable.

    PHP Code:
    <?PHP
    $getNum 
    =$_POST["postNum"];
    $Passtoflash="From Database ";
    $i=0;
    while(
    $i<$getNum){
          echo 
    "&toflash$i=$Passtoflash$i&<br>";
         
    $i++;
    }
    echo 
    "&endOn=$i&";
    ?>
    Actionscript Code:
    var send:LoadVars=new LoadVars();
    var loadPHP:LoadVars = new LoadVars();
    send.postNum=20;
    var i:Number = 0;
    loadPHP.onLoad = function(success:Boolean) {   
        if (success) {
            while (i<this.endOn) {
                trace(this["toflash"+i]);
                i++;
            }
            trace(this.endOn);

        } else {
            trace("Error");
        }
    };
    send.sendAndLoad("http://lwww.domainName/fileName.php",loadPHP,"POST");

    Regards

    Poltuda
    Last edited by poltuda; 10-16-2010 at 11:54 AM.

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    you are correct..

    I missed that fact that he only needs to get the last 20 posts..

    however...
    I know how to use a LoadVar object..(hence why I posted an example of doing so).

    and 'still' recommend it over using the older loadVariables() method.

    I also think your last example is incorrect or at least mis-leading.

    If you, as you say, wanted to send a number to PHP and then retrieve the returned data..

    you would use sendAndLoad().... using two objects one to hold the data being sent..and create another to handle the returned data (text, xml..whatever)



    actionscript Code:
    var returnObject:LoadVars = new LoadVars();
    returnObject.onLoad = function(success:Boolean) {
        if (!success) {
            //returned data failed
        } else {
            //retuend data successful, parse as you see fit
        }
    };
    var sendObject:LoadVars = new LoadVars();
    sendObject.requestPosts = 20;
    sendObject.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm", resultObject, "POST");

    whatever works for you I guess.

    I still dont understand your frame jumping to update data stuff?

    but whatever.. whatever works for the OP as well

  12. #12
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Oh Sure,

    It is for lite or old version,to make a loop to get the total data from server.

    I know this is not a Flash Lite question but still, on flash lite 1.1 you never receive data in one frame without looping.

    which one of the post was incorrect?

    Sorry I not get any resultObject in your code :

    sendObject.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm", resultObject, "POST");

    And it should be .php instead of .cfm


    Regards

    Poltuda
    Last edited by poltuda; 10-16-2010 at 05:29 PM.

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    the URL posted in the example..is just JUNK/fake URL..

    it of course should be whatever .php script you point it too..

    when using sendAndLoad..

    you create an object that sends the data to the php script..

    when you are expecting RETURNED data from that same php script (hence the send AND load)..

    you define an project to handle the returned data. (ie: this return object could be an xml object to parse the returned XML data..or handle the parsing of the string/text data)

    IMHO.. there is no reason why anyone would need to jump frames to update..

    you send all the data to flash at once.. and parse it as once chunk of data..

  14. #14
    Senior Member
    Join Date
    May 2010
    Posts
    178
    sendObject.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm", resultObject, "POST");

    resultObject should be returnObject as per your code.

    I never achieve chunk data in one frame when developing Flash Lite 1.1 apps.

    Please post a sample fla of your method using the above posted php code.

    poltuda
    Last edited by poltuda; 10-16-2010 at 06:11 PM.

  15. #15
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    ahh. I see what you are pointing out now.. it was a typo.. (partial copy from the examples)



    and this isnt Flash Lite forum..so I cant comment on how it works..

    but wouldnt you handle the 'loop' and building of the data done on the PHP side..and send over all the data in one 'transfer'?

    On the flash side of things.. you handle the data as you see fit.

    (depending on how you build/send the data from PHP script)..

  16. #16
    Senior Member
    Join Date
    May 2010
    Posts
    178
    PHP ends its session after all echo-s in each fire.

    sendAndLoad() of object with LoadVars() will till holds. So, I think both the part are doing well what ever data you send and received, it success after ending the PHP session closed.

    But, yes you can build xml format or array or a string from PHP side... which have to phrase inside flash.

    My suggestion is if you are dealing with simple data structure then this process will work, but if you are going to deal will complex data structure with multidimensional arrays and have to keep the security side in mind, then making xml on fly from database with server side languages is the best option on web, till my knowledge.


    Regards


    Poltuda

  17. #17
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    Hey Guys I Must be Stupid or something because I'm lost...

    whispers, your mothered looks like a better route to go because my Website had a button on to exec the PHP code, with a sliding door that opens and display it.

    however i've tried the PHP code with XML support in and i just cant get it to display anything. If i load the php file outside of flash I also just get a blank page. Now if I load my old PHP code outside of flash it works.
    I've never worked with XML at all, but I see flash looks like it really like it

    Although I dont understand this line:
    PHP Code:
    $Passtoflash .= "\t<post user='" $username " . " topic='" . $topic_name . "' />n"; 
    if I Edit the Flash Button and run the script it i get "Trace: Error loading/parsing LoadVars"
    in FL output panel that's using the XML PHP and AC code from whispers. 7th post from the top

    My Flash Version is CS5 but Plz don't ask me to do this in AC3, that makes even less sense to me.

    I've also Noticed that if i use ".=" anywhere the hole thing just dies on me
    I've moved Echo inside of loop, or outside doesn't make a difference

    Also Still to be implemented in this mess is:
    A <a href> tag must also still be used to take the user to that post if clicked on
    Even with my old PHP script the minute I put <a href></a> in Echo - Flash loads Blank

    Cant I maybe Query the SQlite DB and return each result on its own?
    to keep flash happy

    like at the end:
    echo "firstentry=$whatever";
    echo "secondentry=$whatever";

    and so on...

    Loading each result with a different Var for Flash - if so How?


    I'm so Soz for my limited Knowledge on this I've never done SQLite DB, PHP, XML, advance flash stuff before. Learning it all by myself

    Here is my Website if you wanna go take a look at the structure: http://microfusion.mine.nu

  18. #18
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    whispers Thank You, I got it Working just played around with XML a bit
    your PHP and XML code was correct, Don't know why it didn't work the yesterday

    Now i must try to get each line <a href> to the forum... Again Thank You
    I really Appreciate all the Help

  19. #19
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    one last question about the "&"

    in this line:

    PHP Code:
    $Passtoflash .= "<b>$username</b> Posted in the <a href ='http://microfusion.mine.nu/forums/viewtopic.php?$forum_id&$topic_id&p=$post_id#p$post_id'>$topic_name</a> Forum Thread<br />"
    How can i Get Flash to Ignore the two "&" symbols in the hyperlink
    and NOT pass them as Variables because the ahref won't work without the & char
    and if I add them Flash thinks its Variables and then only display in Txt field

    "username Posted in the"

    once
    I know there is a problem with the & char in the <ahref>
    Since the Data is now Passed to FLash and is displays correctly in the Dynamic Txt field.
    HTML Support is on

  20. #20
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    HAHA..

    ok.. yeah sorry to confuse you.. we kinda went off target a bit above..

    but in an effort to give the best solution!..


    Im glad it worked..

    but kinda lost myself now as to what you have done.. and whats working?

    and what you have left to 'clean up'?

    the XML was just a suggestion! "I" always use XML.. for me its easier and more powerful.

    are you going the XML route? or the string route?


    hard to test without the PHP to look at.. see what its sending.. and see what Flash is getting..

    maybe just build up the link on the FLASH side of things?

    and from php only pass vars?

    If you were doing XML..you would just need to wrap that data inside of the CDATA tags..


    CDATA tags make the text sent over in XML to be treated as 'TEXT'..

    (ie:.. sometimes in XML you want to send over HTML tags/data.. well both HTMNL and XML use the <> flags...... so you need to wrap all the HTML data in a CDATA tag.. so Flash doesnt try to parse it like an XML node..and treats it as the data sent over)


    maybe try escaping the & characters?

    like so \&


    so lets get on the same page..and get you rproject working!

Tags for this Thread

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