开发者

What's the correct way to access a field in an array element with php?

I'm getting a few rows from the DB with an ajax call开发者_运维问答 in PHP and I save the result to an array with javascript.

Then I make some changes in the data and wish to update the DB.

So I use another ajax call for that but I can't manage to access the fields inside the rows correctly.

When I try this I get nothing:

echo $bArray[$i].branchId;

When I try this:

echo json_encode($bArray[$i].branchId);

I get ArraybranchId instead of the field value.

What's the correct way to access the field with php?


Try either for array:

$bArray[$i]['branchId']

or for object:

$bArray[$i]->branchId

depending which type $bArray[$i] is (array or object). You have not written in your question, so I showed both ways.


I take it branchId is the name of the field, and you want the value for that field?

If so, it's:

echo $bArray['branchId']; or echo $bArray[$i]['branchId']

Edit: Also, you'll need to make sure you're using mysql_fetch_assoc not mysql_fetch_array!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜