*注-有关完整背景,请参见前面的问题:http://bit.ly/1gaF673
好的,在解决了上面的问题和接下来的几个问题之后。我的表单提交返回我想要的结果。执行此操作的代码如下:
//THIS CODE CONNECTS TO THE NON-WP-TABLES WE MADE INSIDE THE WP DATABASE
global $wpdb;
//get list of localities
$localityRow = $wpdb->get_results( "SELECT Name, LocalityID FROM tblYBSLocality ORDER BY
Name ASC" );
//get list of schools
$schoolRow = $wpdb->get_results( "SELECT Name, SchoolID FROM tblYBSSchool ORDER BY Name
ASC" );
//get school ID if form has been submitted
$SelectedSchoolID = $_GET[\'schools\'];
//get location ID if form has been submitted
$SelectedLocationID = $_GET[\'localities\'];
//get selected school name
$selectedSchoolName = $wpdb->get_var( "SELECT Name FROM tblYBSSchool WHERE
SchoolID=".$SelectedSchoolID );
//get selected location name
$selectedLocationName = $wpdb->get_var( "SELECT Name FROM tblYBSLocality WHERE
LocalityID=".$SelectedLocationID );
//get route ID
$getRouteID = $wpdb->get_results( "SELECT Name, RouteID, Description, RoutePageURI
FROM tblYBSRoute WHERE RouteID IN ( SELECT RouteID FROM tblYBSRouteSchool WHERE SchoolID =
$SelectedSchoolID ) AND RouteID IN ( SELECT RouteID FROM tblYBSRouteLocality WHERE
LocalityID = $SelectedLocationID ) " );
//THIS CODE DISPLAYS THE RESULTS BASED ON WHAT THE USER HAS SELECTED IN THE CODE OMITTED
if (isset($SelectedLocationID) && isset($SelectedSchoolID)) { ?>
<div id="resultsDiv">
<div id="resultsHead">
<h3>Search results for routes between:</h3>
<b><?php echo $selectedLocationName; ?></b> and <b><?php echo $selectedSchoolName; ?>
</b><br />
(Click on route to view timetable and map)
</div>
<div id="routeResult">
<?php
if ($getRouteID) {
foreach ($getRouteID as $route) {
$RouteName = $route->Name;
$RouteID = $route->RouteID;
$RouteDescription = $route->Description;
$RoutePageID = $route->RoutePageURI;
?>
<a href="../../<?php echo $RoutePageID;?>"><b>Route: </b><?php echo $RouteName;?></a> <br
/> <?php echo $RouteDescription;?><br />
<?php
}
} else {
?>
<div id="routeRestult">
<h4>Results:</h4>
No Route found for your selection.<br />
</div><?php } ?> </div></div><?php } ?>
这是正常的,但我想改变发生了什么。目前,有一个指向个人帖子ID的链接,结果就在那里——这太棒了。但我想做些轻蔑的事,把那个帖子放在手风琴里。
我在这里找到了一个起点:http://bit.ly/1nqT6Pw - 但我需要弄清楚如何使它更具体地描述我要做的事情。上面链接中的代码是(正如该帖子中所示):
<?php if (have_posts()): ?>
<div id="accordion">
<?php while (have_posts()) : the_post();?>
<div class="accordion-header">
<h1><?php the_title();?></h1>
<?php the_excerpt();?>
</div>
<div><?php the_content();?></div>
<?php endwhile; ?>
</div>
<?php else:?>
<p><?php _e(\'No posts\'); ?></p>
<?php endif;?>
我知道你可以通过标题、摘录和内容来区分一篇文章,但我似乎无法将其正确地放到手风琴中。
我已将上述代码修改为以下内容:
<div id="routeResult"> <?php
if ($getRouteID) {
foreach ($getRouteID as $route) {
$RouteName = $route->Name;
$RouteID = $route->RouteID;
$RouteDescription = $route->Description;
$RoutePageID = $route->RoutePageURI; ?>
<div id="accordion"> <?php
while (is_single($RoutePageID));?>
<div class="accordion-header">
<h1><?php the_title();?></h1>
<?php the_excerpt();?>
</div>
<div><?php the_content();?></div>
</div><?php } } else { ?>
<div id="routeResult">
<h4>Results:</h4>
No Route found for your selection.<br />
</div> <?php } ?> </div>
这比你想象的要好。它创建div,但除了标题之外没有其他内容(等待它…)但标题不对。它给我的是页面的标题,而不是帖子的标题。
因此while语句检测到yes$RoutePageID有效,并且它是一篇文章,但随后返回当前页面的标题。
是因为我连接了其他表,需要告诉$wpdb返回到原始表吗?或者我应该用get\\u post做些什么(由于需要更多的声誉,无法链接到codex,但我知道该去哪里查找)。
一如既往,我们非常感谢您的任何帮助。谢谢你哟!