我需要從單個列中檢索數據並將其放入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」,...]'當你說「沒有運氣」時,這意味着什麼?在您的服務器端或客戶端代碼執行中,執行的執行方式與您所期望的不同? –