0
$result = mysql_query("SELECT * FROM users");
$values = array();
while($row = mysql_fetch_array($result)) 
{
$values[] = array($row['tried']);
}
return $values;

That only returns the word array when being called as a webservice. What am I missing or doing wrong?

4
  • 2
    You are not echoing anything here, so this is not the code where the problem is. You probably need to show the full code Commented Oct 7, 2010 at 23:18
  • Decide what format you want it in (HTML, XML, json, serialized, comma separated, etc.),and use that. Commented Oct 7, 2010 at 23:19
  • Please explain what kind of web services you're using. Are you using a library? What is the MIME type? Commented Oct 7, 2010 at 23:20
  • what is the structure of your data? what do you expect from the column 'tried'? Commented Oct 7, 2010 at 23:28

3 Answers 3

2

It's not returning the word 'array', it's telling you that what is being returned is an array.

To see what is in the array, use either var_dump($values); or print_r($values);. The only difference is the format of the display.

In addition, I don't believe you need to declare array in your assignment to $values.

$values[] = $row['tried'];

should work. $values will still be an array.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for this worked perfectly...now just need to figure out this " content type of 'text/html', but expected 'text/xml'" error when it returns $values
0

I guess you can try changing the last line to: return json_encode($values);. It should at least let you see what you're doing (and may even be usable, depending on situation).

Comments

0

You don't have to SELECT * if you are only using one column. Just SELECT that column.

If it is printing out array, you are probably calling

echo $values;

This is not going to work. There are many solutions to see what you want, e.g.

foreach ($values as $val) { echo $val; }

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.