Help with reversing results... mySQL-AMFPHP-Flash

I have managed to get everything working good and kinda hit a snag with returning data to flash.

Heres my code in flash:


var conn = NetServices.createGatewayConnection("http://localhost/amfphp/gateway.php");
var myService = conn.getService("shoutBox", this);
function getShouts() {
    myService.getShouts('allShouts');
    myTextField = allShouts;
}

Now heres my problem… I need to be able to return the collumns of my mySQL table to flash, in order of newest to oldest. And so far… I can’t get it to work quite right… My current code sends me a VERY long un-orderly array, that I can only seem to see in the NetDebug window.

GetShouts is where I’m having my problem… :frowning: Any Help? Btw… I’m going to clean it all up once I get it working perfect!


<?php
class shoutBox{
          function shoutBox(){
        $this->methodTable = array(
            "addShout" => array(
              //Echoes the passed argument back to Flash (no need to set the return type
              "access" => "remote",
              "arguments" => array ("userName", "userShout"),
              "returntype" => "recordSet"
              ),
              "getShouts" => array(
              "access" => "remote",
              "arguments" => array ("allShouts"),
              "returntype" => "Array"
              )
        );
      }

      function addShout($userName, $userShout){
          @mysql_connect('localhost', 'root', 'mypass');
        @mysql_select_db('mydb');
        $query="INSERT INTO shoutbox (userName,userShout) VALUES('$userName','$userShout');";
        mysql_query($query);
        mysql_close();
      }
      function getShouts(){
        $myArray = array();
        @mysql_connect('localhost', 'root', 'mypass');
        @mysql_select_db('mydb');
        $sql = 'SELECT * FROM shoutbox';
        $result = mysql_query($sql);
        while ($row = mysql_fetch_assoc($result)){
        foreach($row as $key=>$value){
        array_push($myArray, $key, $value);
        }
        }
        return $myArray;
        mysql_close();
      }
}
?>

you need to ORDER BY your date variable in your getShouts query.

Thanks for the heads up! I found this, and it works: $sql = ‘SELECT * FROM shoutbox ORDER BY id DESC’;

But I still have problems returning it to flash… Augh! Anyone good with AMFPHP around here? Omg… This is embarassing… It’s returning to flash on the NetDebug, yet I can’t seem to figure out where it is returning TO.


DebugId: "0"
EventType: "Result"
MovieUrl: "file:///C|/Program Files/xampp/htdocs/amfphp/services/SQLtesting.swf"
Protocol: "http"
Source: "Client"
Time: 1146469494796
Date (object #1)
....."Mon May 1 00:44:54 GMT-0700 2006"
Result (object #2)
.....[0]: "id"
.....[1]: "39"
.....[10]: "userShout"
.....[11]: "SQL TESTING!"
.....[12]: "id"
.....[13]: "37"
.....[14]: "userName"
.....[15]: "Test Name"
.....[16]: "userShout"
.....[17]: "SQL TESTING!"
.....[2]: "userName"
.....[3]: "Test Name"
.....[4]: "userShout"
.....[5]: "SQL TESTING!"
.....[6]: "id"
.....[7]: "38"
.....[8]: "userName"
.....[9]: "Test Name"