2012-02-16 9 views
1

私は2つのテーブルでのMySQL DBを持っている:
1.カテゴリ - カテゴリID /カテゴリ/説明
2.写真 - PHOTOID /カテゴリID/photodescription /写真フレックス&PHP - PHPのサービスで挿入クエリ

そして、私は、Flash Builderによって自動的に作成されたサービス(CategoryService.php)を持っていますが、2番目のテーブルを取得できません!私は2スパークリストを持っているFlash Builderで

<?php 

class CategoryService { 

    var $username = "root"; 
    var $password = ""; 
    var $server = "localhost"; 
    var $port = "3306"; 
    var $databasename = "teste"; 
    var $tablename = "category"; 

    var $connection; 

    /** 
    * The constructor initializes the connection to database. Everytime a request is 
    * received by Zend AMF, an instance of the service class is created and then the 
    * requested method is invoked. 
    */ 
    public function __construct() { 
     $this->connection = mysqli_connect(
           $this->server, 
           $this->username, 
           $this->password, 
           $this->databasename, 
           $this->port 
          ); 

     $this->throwExceptionOnError($this->connection); 
    } 

    /** 
    * Returns all the rows from the table. 
    * 
    * Add authroization or any logical checks for secure access to your data 
    * 
    * @return array 
    */ 
    public function getAllCategory() { 

     $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");   
     $this->throwExceptionOnError(); 

     mysqli_stmt_execute($stmt); 
     $this->throwExceptionOnError(); 

     $rows = array(); 

     mysqli_stmt_bind_result($stmt, $row->categoryId, $row->category, $row->description); 

     while (mysqli_stmt_fetch($stmt)) { 
      $rows[] = $row; 
      $row = new stdClass(); 
      mysqli_stmt_bind_result($stmt, $row->categoryId, $row->category, $row->description); 
     } 

     mysqli_stmt_free_result($stmt); 
     mysqli_close($this->connection); 

     return $rows; 
    } 

    /** 
    * Returns the item corresponding to the value specified for the primary key. 
    * 
    * Add authorization or any logical checks for secure access to your data 
    * 
    * 
    * @return stdClass 
    */ 
    public function getCategoryByID($itemID) { 

     $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where categoryId=?"); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_param($stmt, 'i', $itemID);   
     $this->throwExceptionOnError(); 

     mysqli_stmt_execute($stmt); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_result($stmt, $row->categoryId, $row->category, $row->description); 

     if(mysqli_stmt_fetch($stmt)) { 
      return $row; 
     } else { 
      return null; 
     } 
    } 

    /** 
    * Returns the item corresponding to the value specified for the primary key. 
    * 
    * Add authorization or any logical checks for secure access to your data 
    * 
    * 
    * @return stdClass 
    */ 
    public function createCategory($item) { 

     $stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (category, description) VALUES (?, ?)"); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_param($stmt, 'ss', $item->category, $item->description); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_execute($stmt);  
     $this->throwExceptionOnError(); 

     $autoid = mysqli_stmt_insert_id($stmt); 

     mysqli_stmt_free_result($stmt);  
     mysqli_close($this->connection); 

     return $autoid; 
    } 

    /** 
    * Updates the passed item in the table. 
    * 
    * Add authorization or any logical checks for secure access to your data 
    * 
    * @param stdClass $item 
    * @return void 
    */ 
    public function updateCategory($item) { 

     $stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET category=?, description=? WHERE categoryId=?");  
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_param($stmt, 'ssi', $item->category, $item->description, $item->categoryId);  
     $this->throwExceptionOnError(); 

     mysqli_stmt_execute($stmt);  
     $this->throwExceptionOnError(); 

     mysqli_stmt_free_result($stmt);  
     mysqli_close($this->connection); 
    } 

    /** 
    * Deletes the item corresponding to the passed primary key value from 
    * the table. 
    * 
    * Add authorization or any logical checks for secure access to your data 
    * 
    * 
    * @return void 
    */ 
    public function deleteCategory($itemID) { 

     $stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE categoryId = ?"); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_param($stmt, 'i', $itemID); 
     mysqli_stmt_execute($stmt); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_free_result($stmt);  
     mysqli_close($this->connection); 
    } 


    /** 
    * Returns the number of rows in the table. 
    * 
    * Add authorization or any logical checks for secure access to your data 
    * 
    * 
    */ 
    public function count() { 
     $stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename"); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_execute($stmt); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_result($stmt, $rec_count); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_fetch($stmt); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_free_result($stmt); 
     mysqli_close($this->connection); 

     return $rec_count; 
    } 


    /** 
    * Returns $numItems rows starting from the $startIndex row from the 
    * table. 
    * 
    * Add authorization or any logical checks for secure access to your data 
    * 
    * 
    * 
    * @return array 
    */ 
    public function getCategory_paged($startIndex, $numItems) { 

     $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?"); 
     $this->throwExceptionOnError(); 

     mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems); 
     mysqli_stmt_execute($stmt); 
     $this->throwExceptionOnError(); 

     $rows = array(); 

     mysqli_stmt_bind_result($stmt, $row->categoryId, $row->category, $row->description); 

     while (mysqli_stmt_fetch($stmt)) { 
      $rows[] = $row; 
      $row = new stdClass(); 
      mysqli_stmt_bind_result($stmt, $row->categoryId, $row->category, $row->description); 
     } 

     mysqli_stmt_free_result($stmt);  
     mysqli_close($this->connection); 

     return $rows; 
    } 


    /** 
    * Utility function to throw an exception if an error occurs 
    * while running a mysql command. 
    */ 
    private function throwExceptionOnError($link = null) { 
     if($link == null) { 
      $link = $this->connection; 
     } 
     if(mysqli_error($link)) { 
      $msg = mysqli_errno($link) . ": " . mysqli_error($link); 
      throw new Exception('MySQL Error - '. $msg); 
     }  
    } 
} 

?> 

、最初のものは、すべてcategorysを持っており、それが通信員写真と他のものを移入したときにselectedItem私はしたいです。 私はデータベースで動作するクエリを持っていますが、PHPに挿入することはできません。 これはクエリです:

SELECT TC.*, TP.photodescription , TP.photo FROM category TC inner join photos TP on TC.categoryId = TP.categoryId 

私はこれをどのように行うことができます! 「聞いてくれてありがとう」と感謝します。

EDIT:

<fx:Script> 
    <![CDATA[ 
     import mx.controls.Alert; 
     import mx.events.FlexEvent; 

     import spark.events.IndexChangeEvent; 

     protected function list_creationCompleteHandler(event:FlexEvent):void 
     { 
      getAllCategoryResult.token = categoryService.getAllCategory(); 
     } 


     protected function list2_creationCompleteHandler(event:FlexEvent):void 
     { 
      getAllphotosResult.token = photosService.getAllphotos(); 
     } 

     protected function list_changeHandler(event:IndexChangeEvent):void 
     { 
      category = list.selectedItem; 
     } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <s:CallResponder id="getAllCategoryResult"/> 
    <categoryservice:CategoryService id="categoryService" 
            fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
            showBusyCursor="true"/> 
    <valueObjects:Category id="category"/> 
    <s:CallResponder id="getAllphotosResult"/> 
    <photosservice:photosService id="photosService" 
            fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
            showBusyCursor="true"/> 
</fx:Declarations> 
<s:List id="list" x="197" y="127" creationComplete="list_creationCompleteHandler(event)" change="list_changeHandler(event)" 
     labelField="category"> 
    <s:AsyncListView list="{getAllCategoryResult.lastResult}"/> 
</s:List> 
<s:List id="list2" x="708" y="127" creationComplete="list2_creationCompleteHandler(event)" 
     labelField="photo"> 
    <s:AsyncListView list="{getAllphotosResult.lastResult}"/> 
</s:List> 

これは私の.mxmlの一例です。
「selectedItem」では、categoryIdに基づいて2番目のリストを変更する方法はありますか。
いくつか例を教えてください。 ありがとうございました..

答えて

0

FLASHBuilderがCRUD(作成、読み取り、更新、削除)クラスを作成しました。これはあなたの1つのカテゴリテーブルに基づいています。 var $tablename = "category"; - カテゴリの結果のみを返します。

  1. カスタムあなたのFlashBuilderプロジェクトからクラスを削除し、FlashBuilderに更新されたファイルをインポートし、あなたのJOINステートメントを使用して生成されたクラスの新しいメソッドを書く:あなたは、あなたはいくつかの選択肢を持って、JOINをしたい場合既存のPHPクラスとして。

  2. 写真テーブル用に2番目に生成されたPHPクラスを作成し、その結果をFlexアプリケーション内で結合します。

  3. 複数のデータベーステーブルから取得したデータを返すJOIN操作には、フィールドの結合オプションを使用します。 (おそらく最良のオプション)

これを行う方法の詳細については、以下を参照してください。http://help.adobe.com/en_US/Flex/4.0/AccessingData/WSbde04e3d3e6474c4-668f02f4120d422cf08-7ff7.html

+0

おかげで全体の説明のために多くのことを!私は本当に試しましたが、私はそれを達成していません。 – Rpgccv

+0

私は私の.mxmlで投稿を編集します。あなたが私を助けてくれることを願います。再度、感謝します。 – Rpgccv