选择从SQL表到Flash

时间:2015-06-23 03:39:47

标签: php mysql actionscript-3

我有一个100行的SQL表。每行都有一个日期。

我想检索特定日期的信息。

示例: 使用Flash,用户选择日期12/11/2014,AS3代码将显示与此日期匹配的所有值(我的表的每一列)。 在这个例子中,它将显示" firstname:As de trefle,tome 1:10 ......等等#34;因为它是唯一符合此日期的条目。

到目前为止,我已经设法从用户​​名中选择AS3中的变量,如下所示:

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 = evt.target.value;

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

    // 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)
    myRequest.data = 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
    myLoader.load(myRequest);

    //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 = evt.target.data.totalItem

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

    //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;
}   

在我的sql_result.php中:

<?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;
 }

 $counter++;
 }


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


// free resources and close connection
 mysql_free_result($sql_result);
 mysql_close($connection);

?>

如何使用日期而不是用户名检索变量?

而且,更复杂的是,我如何同时使用它们? (例如:我选择日期和用户名&#34; John&#34;它显示了我的表中日期和用户名匹配的所有变量?

感谢您的帮助,

修改

所以,我在我的AS3代码中更改了这些标签:

memberCombo.prompt = "Please select a date";
memberCombo.addItem( {label: "2015-06-23" } );
memberCombo.addItem( {label: "06/23/2015" } );
memberCombo.addItem( {label: "23-06-2015" } );

并在我的PHP代码中:

我已经改变了

$username= $_POST['username'];

通过

$date = $_POST['date'];

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

通过

 $sql = "SELECT domain FROM d_table where date = '$date'";

但似乎我的Flash应用程序找不到任何&#34;域名&#34;这个日期。 没错。它只是找不到任何东西。

知道为什么吗?

0 个答案:

没有答案