开发者

Flash app with a Search function through a MySql Database (using php)

开发者 https://www.devze.com 2023-03-06 05:52 出处:网络
I need some help with a flash app im currenctly programming. I have a management flash app that does some operations in a MySql databases. I have had some problems, but for the most part, I have been

I need some help with a flash app im currenctly programming.

I have a management flash app that does some operations in a MySql databases. I have had some problems, but for the most part, I have been able to press on. I'm a flash AS3 newb, so bear that in mind.

My actual problem is that I need to do a "Search" module, and I need it to print several results at once. I am although unsure how to get the results on flash. what I have been doing now is calling a php script that, after doing its operation, does something like (for example):

print "Name=".row[1]."&ID=".row[0];

Then, the flash grabs the return value for the several fields. What I now need, would be to get the Name1=something&Name2=somethingelse&Name3=EvenSomethingElse , but I see no way of that happening. I also believe that I am overcomplicating something that should be fairly simpler than this. I would like to ask how do I get a search with several entries at once. This is a dynamic search, so I need to do something that is able to function with 1 result only or several at a time.

I am asking a bit losely because I really dont think my code is the best at the moment. What I have been doing was finding out how many entries would be positive (for ex开发者_Python百科ample, how many users called marco) and then would call the php once inside a cicle while i

So, help me out please, maybe link to a tutorial or something, because I believe there is a simpler way to do this.

Thank you.

Marco Roberto.


If I understand you correctly, you need to fetch some results from a MySQL database and return the values to Flash. The best way to do this would be to get all the results from the database with PHP, the basic way would be to use the mysql_query functions and the more advanced way would be to use PDO.

Using PHP, you could create a file which returns an XML structure which you could then parse with AS3. As far as I know, AS3 has good built-in functions for parsing XML so that should be an easy task.

PHP Example code:

<?php
    $content = '<?xml version="1.0"?><items>';

    $results = mysql_query("SELECT id, name FROM items WHERE name = '$searchQuery';");
    while ($row = mysql_fetch_assoc($results){
        $content .= '
            <item>
                <id>'.$row['id'].'</id>
                <name>'.$row['name'].'</name>
            </item>';
    }

    $content .= '</items>';
    echo $content;
?>

This is what the output could look like:

<?xml version="1.0"?>
<items>
    <item>
        <id>1</id>
        <name>Result one</name>
    </item>
    <item>
        <id>2</id>
        <name>Result two</name>
    </item>
    <item>
        <id>3</id>
        <name>Result three</name>
    </item>
</items>

As for the search query, you can send it to the PHP file using the URLRequest library which you can find more information about here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLRequest.html

Here is a demo on how to send variables to the PHP file using URLRequest and AS3: http://rickydoesit.com/actionscript-3/how-to-connect-to-php-with-actionscript-3-and-post-variables-to-php/

And here is some help regarding parse the XML file with AS3: http://blog.six4rty.ch/tutorials/flash-cs3-loading-an-xml-with-as3/


Here is a video tutorial:

http://gotoandlearn.com/play.php?id=20

It uses actionscript 2 but it should be trivial to adapt to as3. Basically the solution is to write a for-each look in php and output an XML string with all results from the query. Once you have this structured data set back in flash you can do whatever your hearts desire with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消