• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How to get a result from a database to check if record exists?

New Here ,
Nov 03, 2013 Nov 03, 2013

Copy link to clipboard

Copied

Hello guys,

I'm trying to access a record from a table in the database to check if exists to select a checkBox.

Here are my codes so far.

This is the php code:

public function mpiIICheckIfExist($item) {

  $stmt = mysqli_prepare($this->connection,

  "SELECT mpiIIId

  FROM $this->wo2mpi2ii

  WHERE wo2mpiId = ? AND mpiIIId = ?

  LIMIT 1"

  );

  $this->throwExceptionOnError();

  mysqli_stmt_bind_param($stmt, 'ii', $item->wo2mpiId, $item->mpiIIId);

  $this->throwExceptionOnError();

  mysqli_stmt_execute($stmt);

  $this->throwExceptionOnError();

  $rows = array(); 

  mysqli_stmt_bind_result($stmt, $row->mpiIIId);

  while (mysqli_stmt_fetch($stmt)) {

       $rows[] = $row;

       $row = new stdClass();

       mysqli_stmt_bind_result($stmt, $row->mpiIIId);

     }

  mysqli_stmt_free_result($stmt);

     mysqli_close($this->connection);

     return $rows;

  }

When I test the code in Flash Builder like this {wo2mpiId:1, mpiIIId:1} I get wha I expect "mpiIIId = 1"

My problem is that I can access this variable the way I need to.

Here is my mxml file.

     protected function getIItems(event:FlexEvent):void {

          getMpiII.token = mpiService.getMpiIndividualItems(mpiItemId);

          getMpiII.addEventListener(ResultEvent.RESULT, genItems);

      }

      protected function genItems(event:ResultEvent):void {

          mpiVO.wo2mpiId = mpiId;

          for (var i:int = 0; i < getMpiII.lastResult.length; i++) {

          iBox = new spark.components.CheckBox();

          iBox.id = getMpiII.lastResult.id;

       // ***************** PROBLEM SECTION -- I Trying to do an if statement here but I can't get the return value to compare

          mpiVO.mpiIIId = int(iBox.id);

       //trace(mpiVO.wo2mpiId); // expected value - OK

       //trace(mpiVO.mpiIIId); // expected value - OK

          existMpiII.token = mpiService.mpiIICheckIfExist(mpiVO);

          trace(existMpiII.lastResult[0].mpiIIId);  // NOTHING HERE

       // ***************** END PROBLEM SECTION

          iBox.label = getMpiII.lastResult.individualItem;

       //iBox.addEventListener(MouseEvent.CLICK, checkboxHandler);

          iFormContent.addElement(iBox);

          }

      }

     <fx:Declarations>

       <s:CallResponder id="existMpiII" result="existMpiII.lastResult"/>

       <s:CallResponder id="getMpiII"/>

       <s:CallResponder id="createMpiII"/>

       <wampiservice:WampiService id="mpiService" showBusyCursor="true"/>

     </fx:Declarations>

Please help, if need more codes let me know.

Thank you, Robert

Views

465

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines