doujiexin1136 2013-12-03 22:25
浏览 46
已采纳

如何从MySQL获取JSON信息

I want to ask that while parsing an array there is no problem but when it comes to one line information I couldn't make it work.

For my JSON output:

$sql3 = mysql_query("SELECT description_fr FROM aboutUni where id = 1" ); 
$query = mysql_query("SELECT description FROM aboutUni WHERE id = 1");

echo '{"status":"0",';
echo '"about-uni-desc":"'.$query.'",';
echo '"about-uni-desc-fr":"'.$sql3.'",';
echo '"images": [';

An the result is for query and sql3 variables is Resource id #4 and Resource id #3 Why I can't get the exact information this comes from somewhere that I don't know

  • 写回答

2条回答 默认 最新

  • doufan9377 2013-12-03 22:28
    关注

    Look at the example on php.net: http://us2.php.net/mysql_query

    Do this:

    $sql3 = mysql_query("SELECT description_fr FROM aboutUni where id = 1" ); 
    $query = mysql_query("SELECT description FROM aboutUni WHERE id = 1");
    
    $result1 = mysql_fetch_assoc($sql3);
    $result2 = mysql_fetch_assoc($query);
    
    echo '{"status":"0",';
    echo '"about-uni-desc":"'.$result1['description_fr'].'",';
    echo '"about-uni-desc-fr":"'.$result2['description'].'",';
    echo '"images": [';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效