请问php怎么讲数据库返回的查询数据转化为json数据格式

lw6288656 2013-04-30 10:21:36
在zend 框架里面的
$res=$db->query("select name from job_type where tid=$type")->fetchAll();
我把数组打出来是这个东西:


array(2) { [0]=> array(1) { ["name"]=> string(6) "技工" } [1]=> array(1) { ["name"]=> string(6) "普工" } }




...全文
344 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
一起混吧 2013-05-01
  • 打赏
  • 举报
回复
$res=json_encode($res); echo $res; exit();
lw6288656 2013-04-30
  • 打赏
  • 举报
回复
引用 楼主 lw6288656 的回复:
在zend 框架里面的 $res=$db->query("select name from job_type where tid=$type")->fetchAll(); 我把数组打出来是这个东西: array(2) { [0]=> array(1) { ["name"]=> string(6) "技工" } [1]=> array(1) { ["name"]=> string(6) "普工" } }
我直接这样了,然后他就能返回js json数据格式吗? $res=$db->query("select name from job_type where tid=$type")->fetchAll(); json_encode($res); echo $res; exit(); 然后在js也没这样写的话数据没打出来,我如何查看转化的json数据的具体格式呢,照理说如何我数据取错了,也应该打东西出来啊,但是什么也没有额: if(myXmlHttpRequest.readyState==4){ //alert("返回"+myXmlHttpRequest.responseText); var mes=myXmlHttpRequest.responseText; var mes_obj=eval("("+mes+")"); for(var i=0,mes_obj.length;i++){ alert(mes_obj[i].[name]); } }
深圳phper 2013-04-30
  • 打赏
  • 举报
回复
json_encode
兼哲 2013-04-30
  • 打赏
  • 举报
回复
json_encode 怎么不看手册呢?

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧