#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    46
    Rep Power
    14

    multiple rows from DB to php to flash


    has anyone here ever had any experience pulling multiple rows from a table in a DB with php and then passing those to a flash file via loadvariables().

    i can get one row no problem, but not multiple rows. i've tried just about everything. passing arrays, dynamic variable names... i'm stumped.
  2. #2
  3. No Profile Picture
    Dev
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2001
    Posts
    1,436
    Rep Power
    41
    I don't see anythign preventing you from sending multiple rows, just number them in some way. Put all the data for the first row in vars like this:

    var1_1
    var2_1
    var3_1

    etc.

    No reason you can't do that. It's a cheesy workaround but that's Flash for you. You could also try XML but I don't like the way XML is so bulky and not space efficient, and I try to keep my Flash+PHP programs as tight and efficient as possible.
  4. #3
  5. No Profile Picture
    Shrill Digital God
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Raleigh, NC
    Posts
    64
    Rep Power
    14

    incremented name/value pairs


    In PHP:

    <?

    // Query stuff here


    $current_row = 1;

    while ($fetch = mysql_fetch_array($result)) { echo "&varName".$current_row."=".$fetch["fieldName"]."";
    $current_row++;
    }

    echo "&loaded=1";

    ?>


    In Flash Actionscript:

    count = 0;
    index = 1;

    loadVariables ("php_template.php", "", "POST");

    // Then, with the text field named flashVarName, on a keyframe:

    flashVarName = varName1;

    // Now make buttons to advance / back up in this fashion:

    on (press) {
    if (Number(index) < Number(count)) {
    index = Number(index)+1;
    } else {
    index = 1;
    }
    flashVarName= eval("varName" add index);
    }
    I'm not impatient, I just have a low tolerance for boredom.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    46
    Rep Power
    14
    thanks very much for the suggestions. i need the rows displayed in flash in a list format. i can pass say the first 20 rows like you guys mentioned and then create 20 different movie clips all with different but corresponding variable names. but how do i stop a longer row from wrapping and then overlapping the following movie clip.

    is there a way to dynamically create these movie clips depending on the variables it gets from your php script so i don't have to create 20 movie clips?

    -alligator
  8. #5
  9. No Profile Picture
    Shrill Digital God
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Raleigh, NC
    Posts
    64
    Rep Power
    14

    something like this


    This scenario if you have already loaded your incremented name/value pairs (see my previous example):

    In Flash Actionscript

    // Declare your variables

    x = 1;
    position = 0;

    while (x <= _root.numberRows) {

    // "post"+x being each duplicated clip's new name:

    duplicateMovieClip ("_root.movieClip", "post"+x, x);
    setProperty ("_root.post"+x, _y, position);
    this["post"+x].clip1 = _root.["clip1"+x];
    position = position+64;
    x = x+1;
    }
    I'm not impatient, I just have a low tolerance for boredom.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    46
    Rep Power
    14
    okay so first i tried cutting your action script into flash 5 but i got syntax errors i couldn't figure out, and it wouldn't let me switch back to normal mode, so then i tried to break apart your post and recreate my own example. clearly i still don't understand some things.

    in php4flash_temp.php:

    PHP Code:
    <?
    include("dbconnect_yank.php");
    $query "select topic from topics order by date desc";
    $result mysql_result($query);
    $row mysql_fetch_row($result);

    print 
    "num_rows=" mysql_num_rows($result);
    $x 1;
    while (
    $row) {
            print 
    "value_" $x "=" $row[0];
            
    $x $x 1;
            
    $row mysql_fetch_row($result);
    }
    print 
    "&loaded=1";
    ?>
    i'm not sure what the variable "&loaded" is supposed to be for yet...

    in flash on the main timeline keyframe one there is an instance of a movie clip called "db_text". in it there is a dynamic text field with the variable name "flash_var_name".

    also on keyframe one of the main timeline there is the fallowing action script:

    count = 1;
    position = 0;
    loadVariablesNum ("php4flash_temp.php", 0, "POST");

    then on keyframe two of the main timeline there is this:

    while (count <= num_rows) {
    duplicateMovieClip ("db_text", "dup"+count, count);
    setProperty ("this.dup"+count, _y, position);
    set ("this.dup"+count+".flash_var_name", "value_"+count);
    position = position + 64;
    count = count + 1;
    }
    stop ();

    am i close???
    Last edited by alligatorTim; December 31st, 2001 at 05:18 PM.

IMN logo majestic logo threadwatch logo seochat tools logo