简体   繁体   English

PHP制作基本的产品搜索表格

[英]PHP Making a basic product search form

So I have been working on this thing for a while and am stuck. 因此,我从事此事已有一段时间,被困住了。 Basically I currently have an excel sheet with 2 basic colmns the first has a list of old products and the 2nd column has the new product that replaces them. 基本上,我目前有一个带有2个基本列的excel表,第一个列有旧产品列表,第二列有替换它们的新产品。 I have been working to setup a simple php site where I can type the Old product in and it will state the replacment. 我一直在努力建立一个简单的php网站,在其中可以键入Old产品,并且它将声明替换。 I started out by using arrays where I set the array as the product and all of the keys in the array are the various old products and it looks like this: 我从使用数组开始,在该数组中将数组设置为产品,并且数组中的所有键都是各种旧产品,看起来像这样:

$search = $_POST["search"];
$newprod = array("prod1", "prod2", "prod3");

echo "You searched for the $search<BR>";
echo "This can be replace with these:";

if (in_array("$search", $newprod)) {
    echo "NewProdName";
}

So this worked fine when I used it for a few different products but on the products that have long lists of old products the server doesn't like the array having too many keys so it just stops reading it and gives an error for the page. 因此,当我将其用于几种不同的产品时,这种方法很好用,但是在旧产品列表很长的产品上,服务器不喜欢阵列中的键太多,因此它只会停止读取它并为页面提供错误。 Is there a better way or doing this. 是否有更好的方法或这样做。 I know there is a better more complex way I am just wanting this to be a simple thing that i can figure out and expand on later when I am better with php. 我知道有一种更好的更复杂的方法,我只是希望这是一件简单的事情,我可以在以后对php更好的时候弄清楚并扩展。

Try this 尝试这个

You shouldn't put the variable in quotes. 您不应将变量放在引号中。

if (in_array($search, $newprod)) {
    echo "NewProdName";
}

Remove the quotes from "search" 从“搜索”中删除引号

echo "You searched for the $search<BR>";

Would Become: 会成为:

echo "You searched for the ".$search."<BR>";

And then 接着

if (in_array("$search", $newprod)) {

Would Become: 会成为:

if (in_array($search, $newprod)) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM