0

我正在同时学习 Flash、PHP 和 MySQL,当然这已经成为一个问题。通过教程和从头开始构建代码,我已经能够让我自定义构建的 Flash 应用程序从我的 MySQl 数据库中获取一条数据。这是动作脚本:

gobtn.addEventListener(MouseEvent.CLICK, srchPeople);

function srchPeople(e:MouseEvent):void
{

// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();

// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("http://www.myhost.com/my_php.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);

variables.txtBox = txtBox.text;
variables.sendRequest = "parse";

// Send the data to the php file
varLoader.load(varSend);

// When the data comes back from PHP we display it here     
function completeHandler(event:Event):void
{   
    var phpVar1 = event.target.data.var1;
    //var phpVar2 = event.target.data.var2;

    testBox.text = phpVar1;
    testBox.alpha = 87;
    testBox.autoSize ="left";
    modalBox.alpha = 57;

    modalBox.height = testBox.height + 30;
    modalBox.width = testBox.width + 30;
}
}

ActionScript 中的所有内容都按照预期进行。我将 txtBox 的内容发布到 PHP,然后从 MySQL 数据库中获取,然后显示在 testBox 中……但只有一条信息。我已经尝试了几个小时的 PHP 和查询,试图为该行检索多于一列的信息。我只调用一个变量,如 PHP 文件中所示:

<?php

mysql_connect("localhost", "mwh", "password"); 
mysql_select_db ("mydb");

// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") 
{
// Access the value of the dynamic text field variable sent from flash
$txtBox = mysql_real_escape_string($_POST['txtBox']);

$query = "SELECT fname FROM People WHERE fname='$txtBox'"; 

$result = mysql_query($query);
//$row = mysql_fetch_array($result)
$first_name = mysql_num_rows($result);

if ($first_name == 0)
    //echo "Name does not exist.";
    print "var1 = $result doesn't exist.";
else
{
        $result = mysql_result($result, 0);
                    /// I've tried using other variables
        print "var1=$result has been retrieved from the database.";

}   


}
mysql_close();
?> 

我知道SELECT语句只调用一个变量。我尝试过使用其他人,姓氏年龄地址等,但无法检索它。我尝试将SELECT *与 while 循环一起使用,但没有得到结果。我错过了什么?我尝试使用while循环以及另一个基于 Flash 的变量。似乎无法弄清楚这一点。发布的所有代码都可以工作,我只是坚持如何完成它以检索一行中的所有列信息。所有列数据都将显示在Flash 表单上的testBox.text中。任何帮助表示赞赏。

返回数据的屏幕截图

4

0 回答 0