3

我正在尝试创建一个搜索,以搜索我拥有的谷歌电子表格。

在我的 query.setQuery() 中没有搜索我输入的搜索字符串。

表格也没有正确填充,

我做了一些标签评论,以便我可以包含我所有的代码,因为堆栈溢出只会让我提交 5 个标签

谢谢您的帮助

<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Example of Google Spreadsheet Data Visualisation</title>
</head>

<body>

<form id="form1" name="form1" method="post" onsubmit ="return drawVisualization()"> <label>
<input id="search" name="search" type="text" />
</label>
<label>
<input type="submit" />
</label>

</form>
<p>

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
      google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
    var visualization;

function getSearch() { return form1.elements["search"].value;}

    function drawVisualization() {

      $search = getSearch();
 if ($search > ''){ $search = $search;} else { $search = '';}

 // alert($search);

      var query = new google.visualization.Query(
          '//My link to public google spread sheet');

      query.setQuery("SELECT A ,B, C  where upper(A) like upper('{$search}')  or upper(B) like upper('{$search}') order by A asc label A 'Product', B 'Manufacturer', C 'Category' ");


    //"SELECT guests FROM exp_freeform_entries WHERE ordid='{$_SESSION['eid']}' LIMIT 1");


      query.send(handleQueryResponse);
    }

    function handleQueryResponse(response) {
      if (response.isError()) {
        alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
        return;
      }

      var data = response.getDataTable();

     visualization = new google.visualization.Table(document.getElementById('table'));
     visualization.draw(data, {legend: 'bottom'});

    }

    google.setOnLoadCallback(drawVisualization);
    </script>

   <div id="table"></div>

</div>

</body>
</html>
4

0 回答 0