gpt4 book ai didi

php-mysql 关于获取多节经文的问题

转载 作者:行者123 更新时间:2023-11-29 09:15:12 25 4
gpt4 key购买 nike

找到答案:我正在阅读所有内容并做出决定,非常感谢哈哈哈:D I <3 stackoverflow

对于这个问题的模糊性和缺乏研究,我深表歉意,但我真的不知道如何用谷歌搜索这个问题。

我将圣经经文和圣经章节传递到一个页面中,该页面接受它并从圣经数据库中提取该经文,如下所示

?book=创世记&chapter_number=1&verse_number=1

但是我想要做的是发送多个由“-”分隔的诗句

像这样:

?book=创世纪&chapter_number=1&verse_number=1-2

我真的不知道这是如何运作的。有任何想法吗?

最佳答案

这有效。它允许您给出一系列经文,例如 1,3,4-10。如果没有给出特定的经文,它将返回整个章节。

// Get the book and chapter
$book = isset($_GET['book'])?(string)$_GET['book']:'';
$chapter = isset($_GET['chapter'])?(string)$_GET['chapter']:'';

// Make sure you escape the string to prevent SQL injection
$book = mysql_real_escape_string($book);
$chapter = mysql_real_escape_string($chapter);

// Get the verses as a string.
$verses = isset($_GET['verses'])?trim($_GET['verses']):'';

if ($verses ==='') {
// If no verses are given, TRUE will trick the database
// into returning all verses for the given book.
$verseWhere = 'TRUE';
} else {
// Split it on the commas
$verseRanges = explode(',', $verses);
$verseConditions = array();

// Split each value on '-', if any
foreach($verseRanges as $verseRange) {
$verseRange = explode('-', $verseRange);
// Build a condition
if (count($verseRange) === 1) {
$verseConditions[] = "verse = ".(int)$verseRange[0];
} else {
$verseConditions[] = "verse BETWEEN ".(int)$verseRange[0]." AND ".(int)$verseRange[1];
}
}

// Implode the array to build a list of conditions
$verseWhere = "(".implode(' OR ', $verseConditions).")";
}

// Create the SQL statement
$query = "
SELECT
*
FROM
Bible
WHERE
book = '$book' AND
chapter = '$chapter' AND
$verseWhere";

[编辑]做了一些小的更改,删除了拼写错误并实际运行脚本来测试它。 :)

关于php-mysql 关于获取多节经文的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4371769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com