将数组元素转换成链接,其作用类似于“POST”方法的形式。 [英] Turning an array element into a link, which acts like a "POST" method in a form.
问题描述
我有一个包含表单的网页,如下所示:
I have a webpage which contains a form, like the following:
<Form action="search.php" method="POST">
<fieldset>
<legend> Enter your search below </legend>
<textarea name="query"> </textarea>
</fieldset>
</form>
用户文本从查询
中读取,搜索结果将使用以下部分中的代码显示:
The users text is read from query
and search results are displayed using code in the following section:
if ($_POST['query'])
{
//Users query is read and results from a search API are displayed
}
接下来的事情是,生成一个同义词列表,存储在我在左侧导航栏中显示的一个名为 $同义词
的多维数组中,使用下面的代码。 $ newline
打印一个换行符(如变量名称所示)
The next thing that happens is that a list of synonyms are generated, stored in a multidimensional array called $synonyms
which I have displayed in a left-hand-navigation bar, using the code shown below. $newline
prints a newline (as the variable name suggests)
$同义词
array:
array(3)
{ [0]=> array(2)
{ [0]=> string(9) "chelonian"
[1]=> string(17) "chelonian reptile" }
[1]=> array(6)
{ [0]=> string(7) "capsize"
[1]=> string(11) "turn turtle"
[2]=> string(8) "overturn"
[3]=> string(9) "turn over"
[4]=> string(8) "tip over"
[5]=> string(9) "tump over" }
[2]=> array(4)
{ [0]=> string(4) "hunt"
[1]=> string(3) "run"
[2]=> string(9) "hunt down"
[3]=> string(10) "track down" }
}
输出数组:
foreach ($synonyms as $test)
{ foreach ($test as $test2)
{
echo $test2.$newline.$newline;
}
}
我想要发生的是:
将每个同义词转换成一个可点击的链接。如果用户单击同义词capsize,则将capsize一词发送到同义词(以前查询
)被读取并处理成结果。返回此部分:
Turn each synonym into a clickable link..if the user clicks the synonym "capsize", the word capsize is sent to the section where the synonym(previously query
) is read and processed into results.. ie. back to this section:
if ($_POST['query'])
{
// Synonym is read and results from a search API are displayed
// Previously 'query' was read here
// The cycle continues again
}
任何关于这一点的想法或建议都会很棒,谢谢你们。
Any ideas or suggestions on this one would be great, thanks guys.
推荐答案
您应该以搜索形式使用GET。然后列出如下所示的同义词
You should use GET in search form. Then list synonyms as shown below
foreach ($synonyms as $test)
{ foreach ($test as $test2)
{
// I used <br/> for newline
printf('<a href="search.php?query=%1$s">%1$s</a><br/>', $test2);
}
}
编辑:你应该用$ _GET ['query']替换$ _POST ['query']
And obviously, you should replace $_POST['query'] with $_GET['query']
这篇关于将数组元素转换成链接,其作用类似于“POST”方法的形式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!