据我所知,我有一个搜索查询,PHP但需要进行一些改进:
当我搜索"什么是食物"并且我在数据库中有"什么是食物"时,所有结果都包含关键字"什么","是","食物"之一.期望的行为是显示包含确切短语"什么是食物"的结果(第一个)
只突出显示查询中的最后一个单词,我想突出显示所有单词
期望的行为:正确的答案显示在顶部,无论其在数据库中的位置如何.
我目前的代码是这样的:
if (isset($_GET["mainSearch"]))
{
$condition = '';
$mainSearch = SQLite3::escapeString($_GET['mainSearch']);
$keyword = $_GET['mainSearch'];
$query = explode(" ", $keyword);
$perpageview=7;
if ($_GET["pageno"])
{
$page=$_GET["pageno"];
}
else
{
$page=1;
}
$frompage = $page*$perpageview-$perpageview;
foreach ($query as $text)
{
$condition .= "question LIKE '%".SQLite3::escapeString($text)."%' OR answer LIKE '%".SQLite3::escapeString($text)."%' OR ";
}
foreach ($query as $text_2)
{
$condition_2 .= "bname LIKE '%".SQLite3::escapeString($text_2)."%' OR bankreq LIKE '%".SQLite3::escapeString($text_2)."%' OR ";
}
$condition = substr($condition, 0, -4);
$condition_2 = substr($condition_2, 0, …Run Code Online (Sandbox Code Playgroud) 我有一个从数据库中回显的表单,但问题是当我尝试提交时,只有第一个回显表单提交,其余表示不提交.以下是我的代码.
editquestion.phh
<thead>
<tr>
<th style="width: 5%;">S/N</th>
<th style="width: 20%;">QUESTION</th>
<th style="width: 40%;">ANSWER</th>
<th style="width: 30%;">KEYWORDS</th>
<th style="width: 5%;">SAVE/UPDATE</th>
</tr>
</thead>
<tbody>
<?php
$sql = $db->prepare("SELECT * FROM questions");
$result = $sql->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
$quiz_id = $row['quiz_id'];
$question = $row['question'];
$answer = $row['answer'];
$keywords = $row['keywords'];
echo '<form action="updatequestion.php" method="post" enctype="multipart/form-data">
<tr>
<td><input style="width: 50%" type="text" name="cid" id="cid" value="'.$quiz_id.'"></td>
<td><input type="text" name="question" id="question" value="'.$question.'"></td>
<td><input type="text" name="answer" id="answer" value="'.$answer.'"></td>
<td><input type="text" name="keywords" id="keywords" value="'.$keywords.'"></td>
<td><input type="submit" name="qupdate" …Run Code Online (Sandbox Code Playgroud) 我目前正在使用python进行任务,我需要帮助,而且我需要帮助
编写一个名为longest的函数,它将采用一串空格分隔的单词并返回最长的单词.
例如:
longest("This is Andela") => "Andela"
longest("A") => "A"
Run Code Online (Sandbox Code Playgroud)
这是样本测试
const assert = require("chai").assert;
describe("Module 10 - Algorithyms", () => {
describe("longest('This Is Andela')", () => {
let result = longest("This Is Andela");
it("Should return 'Andela'", () => {
assert.equal(result, 'Andela');
});
});
describe("longest('This')", () => {
let result = longest("This");
it("Should return 'This'", () => {
assert.equal(result, 'This');
});
});
describe("longest(23)", () => {
let result = longest(23);
it("Should return ''", () => {
assert.equal(result, '');
}); …Run Code Online (Sandbox Code Playgroud) 我有一个函数来删除javascript中两个数组之间的非常见元素,但问题是我的代码减少了数组中的一些项目并增加了一些.以下是我的代码
function canFormPairs(cleanSocks, dirtySocks) {
let compared = [];
cleanSocks.forEach(item => {
dirtySocks.forEach(dItem => {
if (item == dItem) {
compared.push(item);
}
});
});
return compared;
}
console.log(canFormPairs([1, 5, 6, 7, 5, 6, 5, 56], [1, 5, 6, 7, 8, 5, 6, 7, 8, 78]));Run Code Online (Sandbox Code Playgroud)
上面的代码给出了
[ 1, 5, 5, 6, 6, 7, 7, 5, 5, 6, 6, 5, 5 ]
Run Code Online (Sandbox Code Playgroud)
而不是期望的结果
[1, 1, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7]
Run Code Online (Sandbox Code Playgroud)
排序时
请问这段代码有什么问题
美好的一天,我试图使用forEach循环从数组中删除重复元素.但是在这个时候我得到了一些错误.以下是我的代码
function removeDup(arr) {
let result = arr.forEach((item, index) => { if (index > 1) item.shift() });
return result;
}
Run Code Online (Sandbox Code Playgroud)
我甚至不确定这段代码是否适用于删除重复项,因为当我在浏览器中运行它时console会出现此错误
if(index> 1)item.shift(); ^
TypeError:item.push不是函数
首先,我如何修复此错误,其次此代码是否可以删除重复项?