0
  $result = mysql_query("SELECT position
        FROM ".$this->table_name."
        WHERE c_name = '".$chName."'");

        while($row = mysql_fetch_array($result)) 
        {
            return(array($row['position']));
        }

I am getting the same value, even if i change the combox... i need the ID of the combox box when its changed. But for every time i select it displays the same value.

function getID($chName) {

}

chName is the value i am getting from combo box from Flex.

0

5 Answers 5

2

You are always returning just the first row. Maybe you want the whole data set and not just the first record. So try this:

$result = mysql_query("SELECT position
    FROM ".$this->table_name."
    WHERE c_name = '".$chName."'");
$retVal = array();
while ($row = mysql_fetch_array($result)) {
    $retVal[] = $row['position']);
}
return $retVal;
Sign up to request clarification or add additional context in comments.

Comments

0

why

 return(array($row['position']));

and not just

return($row['position']);

For any other help you have to provide more informationn (hmtl? output?)

Comments

0

Gumbo's answer is correct.

Notice that unconditionally returning something inside a loop makes the loop itself to be run only once. This is true in general and you should always avoid such a monster :)

If you are a memory saver guy you do a very little memory an CPU improvement:

mysql_fetch_assoc()

that avoids retrieving an integer indexed array you'll not use

Comments

0

Dont use double quotes if you arent wanting variables inside parsed.

$results = array();

// Dont forget you should be escaping $chName
$result = mysql_query("SELECT `position` FROM `{$this->table_name}` WHERE `c_name` = '$chName';");

while($row = mysql_fetch_array($result)) 
{
    $results[] = $row['position'];
}

return $results;

Or

$results = array();

// Dont forget you should be escaping $chName
$result = mysql_query('SELECT `position` FROM `'.$this->table_name.'` WHERE `c_name` = \''.$chName.'\';');

while($row = mysql_fetch_array($result)) 
{
    $results[] = $row['position'];
}

return $results;

Comments

0

The other folks have posted good answer; Just one suggestion - code a DB wrapper class so you don't have to manually fetch arrays all the time, which is a source of constant error. I have my own Query class and after performing a query, I just do $query->dumpResultAsArray() and do the for-each from there.

It's less efficient, but it's more robust and easier to debug.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.