使用JS和PHP SQL Query获取JSON数据[已关闭]

kx1ctssn  于 4个月前  发布在  PHP
关注(0)|答案(1)|浏览(63)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。

这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
12小时前关门了
Improve this question

function fetchBooks() {
  fetch('biblebooks.php')
    .then(response => {
      if (!response.ok) {
        throw new Error('Network response was not ok');
      }
      return response.json();
    })
    .then(data => {
      // Handle the data retrieved from the server
      console.log(data); // Modify this to update your dropdown menus
    })
    .catch(error => {
      // Handle errors
      console.error('There was a problem with the fetch operation:', error);
    });
}

// Call the function to fetch data when needed
fetchBooks();
<?php

// Establish a connection to your database
require 'includes/dbh.inc.php';

// Execute your SQL query
$BookSQL = "SELECT DISTINCT book FROM translationTable";
$BookSTMT = $conn->prepare($BookSQL);
// $BookSTMT->bind_param("s", $UserID);
$BookSTMT->execute();
$BookRESULT = $BookSTMT->get_result();
// Run the query and fetch data

// Convert the data to JSON format
// $data = /* fetched data */;

header('Content-Type: application/json');
echo json_encode($BookRESULT);
?>

我能解释的最好的方法就是用一张照片。我觉得答案就在我面前,但我已经被困在这几个小时了。
我正在开发一个圣经地址导航栏,其中的书籍和章节都存储在一个SQL表中。数据应该显示在3个不同的菜单中。
如果用户更改了翻译,则书籍和章节应反映表中找到的真实的数据。
我在下面得到一个与json相关的错误。我如何才能让它工作并放置在正确的文件夹中?


的数据


sshcrbum

sshcrbum1#

$bookRESULT不是一个可以作为JSON返回的结果数组。您需要从中获取结果。

echo json_encode($BookRESULT->fetch_all(MYSQLI_ASSOC));

字符串

相关问题