第一件事第一:
我今天大部分时间都在浏览这些论坛;stackoverflow论坛;php。net手册;我通过谷歌搜索找到了一堆随机的网站,所以,如果我错过了答案,似乎我在问一个已经回答过的问题,我很抱歉。我可能只是在看同一个问题太久了,没有什么是有意义的。
背景:
我们在wordpress数据库中插入了一些自定义表,因此我可以通过$wpdb连接到这些表。工作连接的代码如下:
global $wpdb;
// get list of localities
$localityRow = $wpdb->get_results( "SELECT * FROM tblYBSLocality ORDER BY Name ASC" );
// get list of schools
$schoolRow = $wpdb->get_results( "SELECT * 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\'];
然后在我的页面后面,我让它做一些事情(scorcery!)
// Create a drop down box for the user to select their location (and one has been done
// for school but I left that out because you get the idea
<select name="localities" style="width: 300px">
<?php
foreach ($localityRow as $locality) {
$LocalityID = $locality->LocalityID;
$LocalityName = $locality->Name;
?>
<option value=<?php echo $LocalityID; ?> <?php if(isset($SelectedLocationID) &&
$SelectedLocationID == $LocalityID) print(" selected")?>><?php echo $LocalityName;?>
</option>
<?php
}
?>
</select>
注意-是的,我知道使用*是不好的,我稍后会解决它-现在我只想让它工作。
利用这个,我可以通过以下步骤完成并生成一系列内容:
// get school ID if form has been submitted
$SelectedSchoolID = $_GET[\'schools\'];
// get location ID if form has been submitted
$SelectedLocationID = $_GET[\'localities\'];
这对我的问题的其余部分并不重要,所以我将继续。
问题:
我将从代码开始。这应该连接到其他一些表并执行一些操作-基于上面检索到的连接和数据:
$selectedSchoolName = $wpdb->get_results( "SELECT Name FROM tblYBSSchool WHERE
SchoolID=".$SelectedSchoolID );
// get selected location name
$selectedLocationName = $wpdb->get_results( "SELECT Name FROM tblYBSLocality WHERE
LocalityID=".$SelectedLocationID );
// get route ID
$getRouteID = $wpdb->get_results( "SELECT * FROM tblYBSRoute WHERE RouteID IN ( SELECT
RouteID FROM tblYBSRouteSchool WHERE SchoolID
=".$SelectedSchoolID.")".$SelectedLocationID);
现在,我认为问题出现在“..$SelectedSchoolID;”部分(以及位置部分,但这已经得到了tldr)。
我想在页面后面做的事情(一旦用户做出选择并提交表单)是获取结果(真想不到!)。
结果分为两部分:
首先,我想说“搜索结果之间的路线:”地点名称和学校名称。第二,我想显示这些结果。但我甚至无法通过第一点,所以让我们先解决这个问题。
我尝试了3种不同的方法:
// FIRST APPROACH
// This kinda works, it echoes the last locality name from the table
// which is better than nothing
<b><?php echo $LocalityName;?></b> and <b><?php echo $SchoolName;?></b><br />
// SECOND APPROACH
// This gives me the white page of death. Which is hilarious because it\'s pretty
// much the exact same as what was used in the option - which worked
<b><?php if(isset($SelectedLocationID) && $SelectedLocationID == $LocalityID) echo
$LocalityName;?></b> and <b><?php if(isset($SelectedSchoolID) && $SelectedSchoolID ==
$SchoolID) echo $SchoolName;?></b>
// THIRD APPROACH
// This also gives me the white page of death. And now I\'m out of ideas.
<b><?php if(isset($SelectedLocationID) && $selectedLocationName == $LocalityName
echo $LocalityName ;?></b> and <b><?php if(isset($SelectedSchoolID) &&
$selectedSchoolName == $SchoolName echo $SchoolName ;?></b>
在我的脑海里(哈哈!)最后两个应该有效。我认为这是“$SelectedSchoolID”;部分,是正确的吗?还是我完全放弃了其他东西?
很抱歉,我想我应该提供尽可能多的细节。非常感谢您的任何帮助。我现在要去敲几下桌子:P