开发者

json not giving back the proper result from database array

I am getting back two rows from my query, I tested it in phpadmin.

In firebug I can only see the data from one row.

What could be wrong that I don't see?

$data = mysql_fetch_assoc($r);

        }
    }

    header('Content-type: application/json');           
    $output = array(
    "check" => $check,
    "users" => $data,
    "testnumberoffrows" => $number
    );

    echo json_encode($output);

in the ajaxfunction

if( data.check ){
    var user = data.users;
    console.log(user);
开发者_运维问答

thanks, Richard


mysql_fetch_assoc() fetches only one row. You need to loop until it returns FALSE, building up an output array.

Something like this:

while (($row = mysql_fetch_assoc($r)) !== FALSE) {
    $data[] = $row;
}


Please try

    $got=array();
    while ($row = mysql_fetch_array($r)) {
        array_push($got, $row);
    }

    mysql_free_result($r);

    header('Content-type: application/json');            
    $output = array( 
        "check" => $check, 
        "users" => $data, 
        "testnumberoffrows" => $number 
    ); 

    echo json_encode($output); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜