I get an associative array back as wel as a normal one with only one row from the db?
I am getting values back and I pass it on to an ajaxfunction with json_encode
The strange thing is that I get {0:val1, val1:val1,1:val2,val2:val2}
back in firebug. I expected to get an array rather than an object - i.e. [val1, val2]
.
This is the query:
$q = "SELECT twitter_id,kindplaatje FROM krv_profielen WHERE twitter_id IS NOT NULL AND kin开发者_如何转开发dplaatje IS NOT NULL";
$r = @mysql_query ($q,$dbc) or trigger_error("Query: $q\n<br />MySQL Fout: " . mysql_error($dbc));// Voer de query uit.
if ($r) {
if (mysql_num_rows($r) >= 1){
$check = "ok";
$data = mysql_fetch_array($r);
Is it a normal response?
Because by default mysql_fetch_array
returns a combined array that is indexed by number and key. See here: http://us3.php.net/mysql_fetch_array
use mysql_fetch_assoc
instead.
That is normal behaviour, ref http://no2.php.net/mysql_fetch_array.
If you don't want that, you could add a second parameter to mysql_fetch_array
, one of:
- MYSQL_ASSOC
- MYSQL_NUM
- MYSQL_BOTH
MYSQL_BOTH
is default.
精彩评论