我有一个Wordpress页面,我正在使用搜索功能,该功能来自亚马逊AWS上托管的数据库。
搜索时,我可以很好地提取数据,但结果显示在搜索栏下方 我希望结果显示在各自的页面上。
我使用之前提出的问题尝试了几项建议,但没有任何效果。
这是我的代码:
<?php
/* Template Name: Database */
?>
<?php
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
if( strlen($query_string) > 0 ) {
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
} //if
$search = new WP_Query($search_query);
?>
<?php get_header(); ?>
<?php get_footer(); ?>
<?php
$db_hostname = 'xxxxxxxxxxxxxxx';
$db_username = 'xxxxxxxxxxxxxxx';
$db_password = 'xxxxxxxxxxxxxxx';
$db_database = 'xxxxxxxxxxxxxxx';
$con = mysql_connect($db_hostname,$db_username,$db_password);
if (!$con){
die('404 Could not connect to server: ' . mysql_error());
}
mysql_select_db($db_database, $con);
global $sf_options;
$sidebar_config = $sf_options['archive_sidebar_config'];
$left_sidebar = $sf_options['archive_sidebar_left'];
$right_sidebar = $sf_options['archive_sidebar_right'];
$blog_type = $sf_options['archive_display_type'];
if ( $blog_type == "masonry" || $blog_type == "masonry-fw" ) {
global $sf_include_imagesLoaded;
$sf_include_imagesLoaded = true;
}
?>
<div class="container-fluid">
<center>
<form role="" method="get" >
<p style="color: #fff;">Search products and services for your business. We make it easier<br />to manage your business operations and make informed purchasing decisions.</p>
<input type="text" name="term" placeholder="Start typing to find a product or business"/>
<span><input type="submit" value="" class="btn btn-default" /></span>
</form>
</center>
</div>
<?php
if (!empty($_REQUEST['term'])) {
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM wpfr_listing WHERE Description LIKE '%".$term."%'";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query)){
echo '<br /> Company: ' .$row['title'];
echo '<br /> Certs: '.$row['certs'];
echo '<br /> Certifier: '.$row['certifier'];
echo '<br /> Address: '.$row['address'];
echo '<br /> Country: '.$row['country'];
echo '<br /> State: '.$row['state'];
echo '<br /> City: '.$row['city'];
}
}
?>
非常感谢提供的任何帮助。
答案 0 :(得分:1)
在此页面上写下
/full/path
在serach结果页面上
<?php if (!empty($_REQUEST['term'])) {
header("location: page_url?term=".$_REQUEST['term']);
}
?>
答案 1 :(得分:0)
因为,你希望通过PHP完成这项工作,所以你就去了。
1)创建一个新页面。 2)让它处理您在此处使用的查询的GET数据。 3)按照您在此页面中的操作打印搜索结果。
现在,在此页面中,您需要执行标题重定向到该页面标题重定向的语法是这样的。
header('Location: http://www.example.com/?sql = <Your Query above>');
这应该为你做。希望这可以帮助。如果您需要任何进一步的信息,请随时发表评论。