我正在制作一个 WordPress 插件来与我们的图书馆系统集成。我正在尝试创建一个带有搜索表单的页面来搜索数据库。我在我们的图书馆服务器上创建了一个 API(它在我们的本地网络上),因此该站点可以与我们的图书馆后端进行交互。
我正在尝试对从 API 中提取的结果进行分页,数据在 json 中。我创建了以下代码来从 API 获取 json 并将其转换为 PHP 数组,但它还没有实现搜索:
add_shortcode("book_search_form", "book_search_form");
function book_search_form() {
$api_url = get_option('api_url');
$api_key = get_option('api_key');
$data = file_get_contents("$api_url/book/index.php/name/awesome/$api_key");
$data = (array)json_decode($data, true);
echo '<pre>';
var_dump($data);
echo '</pre>';
}
这是输出:
array(2) {
[0]=>
array(22) {
["barcode"]=>
string(12) "000015427928"
["name"]=>
string(74) "Janice VanCleave's 201 awesome, magical, bizarre & incredible experiments."
["author"]=>
string(12) "Janice Pratt"
["author_last"]=>
string(9) "VanCleave"
["publisher"]=>
string(11) "Wiley: 1994"
["year_pub"]=>
string(0) ""
["edition"]=>
string(0) ""
["genre"]=>
string(0) ""
["checkout"]=>
string(5) "false"
["series"]=>
string(0) ""
["callnum"]=>
string(5) "507.8"
["fiction"]=>
string(5) "false"
["in_house"]=>
string(5) "false"
["timestamp"]=>
string(10) "1374711656"
["outto"]=>
string(0) ""
["duedate"]=>
string(1) "0"
["ISBN"]=>
string(10) "0585339376"
["media_type"]=>
string(0) ""
["print"]=>
string(5) "false"
["BOXID"]=>
string(0) ""
["uid"]=>
string(1) "0"
["printed"]=>
string(4) "true"
}
[1]=>
array(22) {
["barcode"]=>
string(12) "000015429634"
["name"]=>
string(50) "Our Awesome Earth: Its Mysteries and Its Splendors"
["author"]=>
string(4) "Paul"
["author_last"]=>
string(6) "Martin"
["publisher"]=>
string(35) "Natl Geographic Society: March 1994"
["year_pub"]=>
string(0) ""
["edition"]=>
string(0) ""
["genre"]=>
string(0) ""
["checkout"]=>
string(5) "false"
["series"]=>
string(0) ""
["callnum"]=>
string(3) "050"
["fiction"]=>
string(5) "false"
["in_house"]=>
string(5) "false"
["timestamp"]=>
string(10) "1382550052"
["outto"]=>
string(0) ""
["duedate"]=>
string(1) "0"
["ISBN"]=>
string(10) "0870445456"
["media_type"]=>
string(0) ""
["print"]=>
string(5) "false"
["BOXID"]=>
string(0) ""
["uid"]=>
string(1) "0"
["printed"]=>
string(5) "false"
}
}
我正在尝试创建分页,因为一些查询包含 50 或更多书籍。我以前用 mysql 做过这个,但我不知道如何用一个数组来做。
谢谢!