A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Final php/mySQL question

  1. #1
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520

    Final php/mySQL question

    I have a flash file with the variable "from" and a movieclip called "takensquare". This connects to a database with fields "id", "user", "taken" and "date". The user clicks on a square in the flash file and the square zooms in to reveal a further 10,000 squares. When this loads up I want flash to place movieclips (takensquare) depending on the results from the database.

    PHP Code:
    <?php 

    //this pulls the variables from the flash movie when the user hits submit.  
    $from $_POST ['from'];

    ...
    log in details removed...

    //select squares from database which have already been taken by other users
    $sql "SELECT * FROM `takensquares` WHERE `id` BETWEEN $from AND ($from + 9999) AND taken = 1"
    $result mysql_query($sql) or die(mysql_error()); 
    ?>
    Is the syntax in the SQL query above correct? ie: if "from" in flash was 210,001 then I want all the records between 210,001 and 220,000 selected where taken is equal to 1. I'm not sure how to output the results for the field "id" back in to flash.

    Finally, in flash, I want the movie clip "takensquare" to be duplicated on the stage for each result. The location for each movie clip would be set according to the following formula:
    Code:
    //work out x position for movieclips
    movieclipxlocation = queryresult / 100;
    movieclipxlocation = Math.floor(movieclipxlocation);
    movieclipxlocation = movieclipxlocation * 100;
    movieclipxlocation = queryresult - movieclipxlocation;
    movieclipxlocation = movieclipxlocation - 1;
    movieclipxlocation = movieclipxlocation * 8;
    
    //work out y position for movieclips
    movieclipylocation = queryresult - from + 1;
    movieclipylocation = _ymouse / 100;
    movieclipylocation = Math.floor(movieclipylocation) * 8;
    This is the last hurdle for my project. Thanks to all those who've previously helped out. Much appreciated!

  2. #2
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    Okay; so outputting the vars to flash I would probably need an array. I've put in the following at the end of the php script:

    PHP Code:
    // loop through the array and output the id field of the query
    while($row mysql_fetch_array($result))
    {
    echo 
    "&id";
    $row_count++; 

    Once again I do not know if that is the correct way to put it. Now I need to get the vars into flash. Any ideas?

  3. #3
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    Just found out that the php file is what flash actually reads from so I have in my actionscript
    Code:
    loadVariablesNum("takensquares.php", 0, "POST");
    which I assume flash will keep checking that file for the results when they are finally sent. What I do not know is how to get php to output those results. I actually want flash to pick up the following items from the database - "id", "user" and "date" fields. So to get PHP to output should I put:
    PHP Code:
    <?php 

    //this pulls the variables from the flash movie when the user
    //hits submit.  
    $from $_POST ['from'];

    //connect to the database
      
    $host ""
      
    $user ""
      
    $pass ""
      
    $database ""

    $db_connect mysql_connect($host$user$pass) or die (mysql_error()); 
    $db_select mysql_select_db($database$db_connect) or die (mysql_error()); 

    $sql "SELECT id, user, date FROM `takensquares` WHERE `id` BETWEEN $from AND ($from + 9999) AND taken = 1"
    $result mysql_query($sql) or die(mysql_error()); 

    // loop through the array and output the scores 
    while($row mysql_fetch_array($result))

    echo 
    $result  


    ?>

  4. #4
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    Half a day later and (I think) I got it! Whew!
    PHP Code:
    <?php

    //this pulls the variables from the flash movie when the user
    //hits submit.  
    $from $_POST ['from'];
    $to $POST ['to'];

    //connect to the database
      
    $host "";
      
    $user "";
      
    $pass "";
      
    $database "";

    $db_connect mysql_connect($host$user$pass) or die (mysql_error());
    $db_select mysql_select_db($database$db_connect) or die (mysql_error());

    $query "SELECT * FROM takensquares WHERE id BETWEEN '$from' AND '$to' AND taken = 1";
    $result mysql_query($query) or die(mysql_error());

    // count rows of array
    $num mysql_numrows($result);

    // loop through results of array and print to screen
    $i=0;
    while (
    $i $num) {
    $id=mysql_result($result,$i,"id");
    echo 
    $id,",";
    $i++;
    }
    ?>
    This outputs the results in the following format: 1,25,298,466
    Is this the way they should be output for what I'm trying to achieve (ie: separated by commas?).

    Just a "yes" or "no" would be a nice confirmation

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