0 Replies Latest reply on Nov 3, 2013 7:39 AM by EthanB

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


      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"



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




        $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);




           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[i].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[i].individualItem;

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






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

             <s:CallResponder id="getMpiII"/>

             <s:CallResponder id="createMpiII"/>

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



      Please help, if need more codes let me know.

      Thank you, Robert