不顾安全问题(现在)当使用json_encode显示选择查询的内容时,如何命名对象?
我正在使用json_encode来显示选择查询的内容。 我用:
$sql= {query code};
// created a temp array to hold data and an array for all the results
$resultArray = array();
$tempArray = array();
// looped through every object in the result set
while ($row = $result->fetch_object());
// added it into the results array
$tempArray = $row;
array_push($resultsArray, $temparray);
// encoded the array to a json format
echo json_encode($resultArray);
问:我对象没有名字,所以它很难让我写,可以读出结果并显示它们的任何代码。我如何命名对象?它是我可以添加到表中的条目吗(假设我可以给每个对象使用不同的名称)
你为什么不使用'$ result-> fetch_array()'? – 2015-01-20 20:08:38
很好用于HTML代码片段lol – MightyPork 2015-01-20 20:09:03
而不是$ result-> fetch_object()?会有什么区别?以及如何命名这些对象(我不知道在哪里给出了名字) – 2015-01-20 20:10:05