脚本宝典收集整理的这篇文章主要介绍了php – 使用Column Name从MySQL返回JSON,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$jsonData = array(); if(MysqLi_num_rows($result) > 0){ while ($array = MysqLi_fetch_row($result)) { $jsonData[] = $array; } $json = json_encode($jsonData); echo stripslashes($json); }`
但是,我只得到行值.我想要行值和它们的列名.目前它返回以下JSON.
[["shekhar","Shekhar Chatterjee","https://graph.faceBook.COM/1254850974526564/picture","0"]],[["shek","","0"]]
我想有以下输出:
[{ "user":"shekhar","name":"Shekhar Chatterjee","url":"https://graph.facebook.com/1254850974526564/picture","stat":"0" },{ "user":"shekhar","stat":"0" }]
干得好
$jsonData = array(); if(MysqLi_num_rows($result) > 0){ while ($array = MysqLi_fetch_assoc($result)) { $jsonData[] = $array; } $json = json_encode($jsonData); echo stripslashes($json); }
以上是脚本宝典为你收集整理的php – 使用Column Name从MySQL返回JSON全部内容,希望文章能够帮你解决php – 使用Column Name从MySQL返回JSON所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。