lundi 22 juin 2015

select values of a particuliar date from a SQL table to Flash

I've got a SQL table with 100 lines. Each line got a date.

I'd like to retrieve the info for a particular date.

Exemple : With Flash, the user select the date 12/11/2014 and the AS3 code will display all the values (each columns of my table) that match this date. In this exemple it will display "firstname : As de trefle, tome 1 : 10...etc" as it's the only entry that matches this date.

So far I've managed to select variables, in AS3, from users name, like that :

memberCombo.prompt = "Please select a user";
memberCombo.addItem( {label: "as de trefle" } );
memberCombo.addItem( {label: "kathy" } );
memberCombo.addItem( {label: "peter" } );
memberCombo.addEventListener(Event.CHANGE, checkComplete);

function checkComplete(evt:Event):void {

    // Create A new URLVariables instance to store the variable
    var myVariables:URLVariables = new URLVariables();

    // Create a variable (e.g. candidate) to send
    myVariables.username =;

    // Create a new URLRequest instance sending data to "ascom01.php"
    var myRequest:URLRequest = new URLRequest("");

    // Send data using the POST method
    myRequest.method = URLRequestMethod.POST;

    // The data property of the request is set to the
    // URLVariables instance (myVariables) to send to the PHP file.
    // Note: myVariables stored the variable (e.g. candidate) = myVariables;

    // Create a new instance of the URLLoader class to work with.
    // URLLoader.load( ) method should be used when we need the 
    // sent variables returned back to Flash ActionScript.
    var myLoader:URLLoader = new URLLoader;

    //specify dataFormat property of the URLLoader to be "VARIABLES"
    //This ensure that the variables loaded into Flash with the same variable names
    myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

    //Load the PHP file by using URLRequest

    //Listen when the loading of data COMPLETE
    //Call the loadComplete function when the loading COMPLETE
    myLoader.addEventListener(Event.COMPLETE, loadComplete);


// This is the function that display the data returned back from PHP file
function loadComplete(evt:Event):void {

    //Display the value with variable name "totalItem"
    total_txt.text =

    //Get the value (string) with variable name "phpConfirm"
    var myResult:String =;

    //Split the string into an Array
    var myArray:Array = myResult.split("|");
    //output_txt.text = "The number of items are: " + myArray.length;

    var finalString = "";
    var i:int;

    for (i = 0; i < myArray.length; i++) {

        finalString = finalString + myArray[i] + "<br>";


    output_txt.htmlText = finalString;

And in my sql_result.php :


$username = $_POST['username'];

// create connection
 $connection = mysql_connect("****.perso", "root", "root") or die ("Couldn't connect to the server.");

// select database
 $db = mysql_select_db("dbase", $connection) or die ("Couldn't select database.");

// create SQL
 $sql = "SELECT domain FROM d_table where username = '$username'";

// execute SQL query and get result
 $sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");

// get number of rows in $result.
 $num = mysql_numrows($sql_result);

$phpConfirm = "";

$counter = 0;

while ($row = mysql_fetch_array($sql_result)) {

 $domain = $row["domain"];
 if ($counter == 0) {
 $phpConfirm .= $domain;
 } else {
 // Use a item limiter "|" to seperate the records
 $phpConfirm .= "|" . $domain;


echo "phpConfirm=" . $phpConfirm . "&totalItem=" . $num;

// free resources and close connection


How can I retrieve the variables with the date and not the username ?

And, more complex, how can I use both ? (exemple : I choose the date AND the username "John" and it shows me all the variables of my table where the date and the username matches ?

Thank you for your help,

Aucun commentaire:

Enregistrer un commentaire