-1

我尝试在执行时形成数组:

$result = mysql_query("SELECT * FROM data WHERE company='$companyID'", $db);
        if (mysql_num_rows($result) > 0) 
        {       
            $resultData = mysql_fetch_array($result);
            do
            {           
                $json[] = array('product' => $resultData['product'], 'title' => $resultData['title']); 
            }       
            while($resultData = mysql_fetch_array($result));
            echo json_encode($json);
        }

退出时所有数据为空(错误):

"[{"product":"","title":""},{"product":"","title":""},{"product":"","title":""},{"product":"","title":""}]"
4

1 回答 1

0

它真的给你一个错误吗?

尝试打印出你的输出,看看你是否真的从 mysql 获取任何东西

$result = mysql_query("SELECT * FROM data WHERE company='".$companyID."'", $db);
        if (mysql_num_rows($result) > 0) 
        {       

            while($resultData = mysql_fetch_array($result))
            {
              echo '<pre>';
              print_r($resultData);
              echo '</pre>';
            }
        }

如果您确实以这种方式获得输出,只需将 {} 之间的内容替换为 while echo json_encode($json);

希望这可以帮助。

于 2013-09-09T22:24:19.807 回答