我想选择表格的最后一行,并将所有值保存到单独的 JavaScript 变量中。我在 PHP 中使用了查询:
$sql = "从读取 ORDER BY id DESC LIMIT 1 中选择 *";
选择表格的最后一行。我不知道如何继续。
最佳答案
PHP:
$sql = "SELECT * from reading ORDER BY id DESC LIMIT 1";
if ($query = mysqli_query($link, $sql)) {
// fetch one result
$row = mysqli_fetch_row($query);
echo json_encode($row);
}
jQuery:
// sample variables
var username = "";
var password = "";
var phpUrl = 'http://sampleurl.com/mypage.php';
$.getJSON(phpUrl, function (result) {
$.each(result, function (data) {
// if data sent back is eg data:[{username:'sample', password:'sample'}]
// then you fetch and save as
username = data.username;
password = data.password;
});
});
关于javascript - 如何从 MYSQL 获取单个值并将其保存到 JavaScript 变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36928194/