我需要从单个列中检索数据并将其放入API(Json)中,但出于某种原因,我也从列中获取标题。检索单个列的值
$sql = "SELECT workingJson FROM dataTable";
我认为它会像workingJson.Value
,但没有运气。
这里是API.php根据您的意见
// Create connection
$con=mysqli_connect("localhost","user","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT column1 FROM database";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($con);
@WillemMassoels我已经编辑按你的意见我的回答。 –
恐怕没有运气,谢谢麦克! –
@WillemMassoels我认为你需要提供更多的调试信息。我所展示的将返回一个JSON表示,如'[“somevalue”,“someothervalue”,...]'当你说“没有运气”时,这意味着什么?在您的服务器端或客户端代码执行中,执行的执行方式与您所期望的不同? –