简体   繁体   English

基于PHP数组字段的搜索

[英]Search based on PHP array field

i am trying to do google search from my page and the search is based on specific set of strings.so the following code has a PHP array field with some values ..so if i need to use them when performing search ,how to do that,i tried to work on following code but it is not working . 我正在尝试从我的页面进行谷歌搜索,并且搜索是基于特定的strings.so的,因此以下代码具有一个带有一些值的PHP数组字段..so如果我在执行搜索时需要使用它们,该怎么做,我尝试处理以下代码,但不起作用。

enter code here


    <head>
    <meta charset="utf-8">
     <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
     <?php $fieldArray=array('fruits','gold','pen');?>
     <script>
     function searchLink()
      {
    var link1 = document.getElementById("search").value;            
     window.location.href = 'https://www.google.co.in/?q='+link1;
     }
     $(function() {
     var availableTags = <?php echo json_encode($fieldArray)?>
     $( "#search" ).autocomplete({
     source: availableTags
     });
      });
     </script>
     </head>
     <input type="text" name="search" id="search" style="width:400px;"/>
     <input type="button" name="searchBtn" id="searchBtn" value="Search"  onclick="searchLink()"/>

I think you want " fruits,gold,pen " as autocomplete in search box. 我认为您要在搜索框中将“ fruits,gold,pen ”作为自动完成功能。

In js You missed semicolon(;) after var declaration. 在js中,您在var声明后错过了分号(;)

var availableTags = <?php echo json_encode($fieldArray)?>;

失踪;

var availableTags = <?php echo json_encode($fieldArray)?>;

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

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