Kevin
Kevin

Reputation: 23634

Array return type problem in PHP

function showFields($selClient) 
    {
        $result = mysql_query("SELECT * FROM project WHERE projectid = $selClient");
        $values = array();
        while($row = mysql_fetch_array($result)) 
        {
            $values[] = array($row['clientname'],$row['prospect'],$row['salesperson']);
        }
        return $values;

  }

When i return the values to Flex, i am not able catch individual elements. When i trace i get all values stored in a single array...

I am slightly confused...,.

var editField:Array = event.result as Array; 
        Alert.show(editField[0]);

This returns all the values in the Array, instead of the 0th element.

Upvotes: 0

Views: 399

Answers (2)

Mathew
Mathew

Reputation: 8279

Also, if you are only returning specific columns, why select them all? This will function will return the same data and as it only selects what you need, will be faster. In this case the select is so simple that the time difference will be virtually 0, but it's a good habit to get into for when your db queries start getting more complex.

function showFields($selClient) 
{
    $result = mysql_query("SELECT clientname, prospect, salesperson FROM project WHERE projectid = $selClient");
    $values = array();
    while($row = mysql_fetch_array($result)) 
    {
        $values[] = $row;
    }
    return $values;
}

Upvotes: 1

dusoft
dusoft

Reputation: 11469

you could do: Alert.show(editField[0][0]);

if i understand it correctly...

you need to iterate over two arrays (two levels)

Upvotes: 1

Related Questions