0

我在 flex 中做了一个小项目。用户可以查找书评。当输入书名时,我会返回所有评论,而不是该特定书的评论。

我的代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

           >
<fx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;

        public function handleMenu(event:ResultEvent):void{
            DescrBooks.dataProvider = event.result.menu.menuitem;
        }
        public function Start():void{

            //favorieten.addEventListener(ResultEvent.RESULT,handleMenu);
            favorieten.send();
        }

        public function ShowBooks(SelectedBooks:Object):String{
            var descr:String = SelectedBooks.itemDesc;

            var D:String = descr

            return D;   

        }
    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here     

    -->

    <s:HTTPService id="favorieten" 
                   url="http://www.gertjanvanhove2012.dreamhosters.com/script/ReviewsTest.php" method="POST"
                   result="handleMenu(event)"
                   >
        <s:request xmlns="" >
            <voorwerp>{TextTI.text}</voorwerp>
        </s:request>

    </s:HTTPService>
</fx:Declarations>


<mx:VBox x="14" y="60" width="744" height="450">
    <mx:Repeater id="DescrBooks" maxWidth="450">
        <mx:HBox>

            <mx:Text text="{ShowBooks(DescrBooks.currentItem)}" maxWidth="450" />

        </mx:HBox>  
    </mx:Repeater>
</mx:VBox>
<s:Button x="14" y="25" label="Button" click="Start()"/>
<s:TextInput x="92" y="25" id="TextTI"/>
</s:Application>

我的php脚本:

<?php
header("Content-type: text/xml");
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// cache wordt uitgeschakeld om zeker te zijn dat de gegevens uit de API gelezen worden en niet uit de cache van de webbrowser
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//alle gegevens om connectie te leggen naar de databank
    $host = "mysql.imd2012.dreamhosters.com";
    $user = "*********";
    $pass = "*********";
    $database = "gertjanvanhove2012";
//connectie leggen naar de databank
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
//gegevens gaan halen uit de databank
if(!isset($_GET['voorwerp'])){

$query = "SELECT * FROM RMA_Review ";

}
else{

$_GET['voorwerp'] = $tit;
$query = "SELECT * FROM RMA_Review where Title='".$tit."'";
}
$menu_result = mysql_query($query, $linkID) or die("Data not found.");
//starten met de opbouw van de string die de XML code bevat
$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml_output .= "<menu>\n";
//voor elk menu item de nodige gegevens neerschrijven
for($x = 0 ; $x < mysql_num_rows($menu_result) ; $x++){
$itemrow = mysql_fetch_assoc($menu_result);
$xml_output .= "\t<menuitem>\n";
$xml_output .= "\t\t<itemID>" . $itemrow['ReviewId'] . "</itemID>\n";
$xml_output .= "\t\t<itemLabel>" . $itemrow['Title'] . "</itemLabel>\n";
$xml_output .= "\t\t<itemDesc>" . $itemrow['Review'] . "</itemDesc>\n";
$xml_output .= "\t\t<itemAutheur>" . $itemrow['Autheur'] . "</itemAutheur>\n";
$xml_output .= "\t</menuitem>\n";
}
$xml_output .= "</menu>\n";
//de volledige XML string in de response echo'n
echo $xml_output;?>

表 RMA_Reviews 如下所示:(无法发布屏幕截图,因为我没有足够的代表)

http://oi39.tinypic.com/2cxtez5.jpg

所以我的问题是:我怎样才能只显示你在文本字段中输入的书籍的值。

4

1 回答 1

0

在我看来,您没有将“标题”变量传递给您的 php 脚本。

尝试通过 URLVariables 添加它,如下例所示:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html#includeExamplesSummary

编辑:哎呀,对不起,我猜你知道!在上面的代码中重读它......你能确认变量在 php 中传递是应该的吗?

于 2013-08-12T10:24:03.740 回答