0
目前我有一个索引页面,它使用simpleXML显示来自XML页面的值。而一个打印到另一个页面的搜索功能,我想要做的是刷新首页,以便在点击按钮时仅显示搜索结果。使用XPath和php进行搜索
索引页。
<?php
$action = "searchFunctionDescription.php";
?>
<form name="search" method="get" action=<?php echo "\"$action"?>">
<input name="txtSearch" type="text" id="txtSearch" size="30"/>
<input type="submit" value="Search" />
<?php
// load the xml file into a simplexml instance variable
$holiday = simplexml_load_file('holidays.xml');
// draw a table and column headers
echo "<table border=\"1\">";
// iterate through the item nodes displaying the contents
foreach ($holiday->channel->item as $holiday) {
echo "<tr><td><a href=\"{$holiday->link}\">{$holiday->title}</a>" . "<br />" .
"{$holiday->pubDate}" . "<br />" .
"{$holiday->description}</td>" . "<br />" .
"</tr>";
}
echo "</table>";
?>
然后我有我的searchProcessDescription.php页
<?php
// create an instance
$holidayDoc = simplexml_load_file('holidays.xml');
// Passes txtSearch to current script from searchFormDescription.php
$txtSearch = $_GET['txtSearch'];
// Informs user of what they have searched
echo "Showing Results for <strong>$txtSearch</strong>";
// set the query using the description
if (!is_null($txtSearch)) {
$qry = "//channel/item[description[contains(text(),\"$txtSearch\")]]";
}
else {
// blank search entered so all holidays are shown.
$qry = "/channel/'ALL'";
}
// execute the xpath query
$holidays = $holidayDoc->xpath($qry);
// now loop through all holidays and entered results into table
echo "<table border=\"0\">\n";
foreach ($holidays as $holiday)
{
echo "<tr>\n";
echo "<td><a href=\"{$holiday->link}\">{$holiday->title}</a></td>";
echo "<td>{$holiday->description}</td>";
echo "<td>{$holiday->pubDate}</td>";
echo "<td><input type=\"checkbox\" name=\"saveCB\" value=\"3\"/></td>";
echo "</tr>\n";
}
echo "</table>\n";
?>
有一个简单的方法来此过程中添加到索引页面,该页面被点击搜索按钮时刷新?
感谢
有一些错误,我正在会见了: 注意:未定义的变量:节日第65行 注意:试图让行非对象的属性65 注意:试图让非财产上线65 -object 警告:未定义变量::行动作77 – 2012-03-28 11:12:10
对不起,则应在此处修改:为第65行 通知的foreach()提供参数无效 <形式名称=“搜索”方法=“POST” action =#“> 其他错误是奇怪的,所有变量似乎inizialized,行号不正确:我所有的脚本有59行! – Gian 2012-03-28 13:49:27
我找到了...请检查变量$ holidayDoc和$ holiday,我修改了附加的代码,对不起 – Gian 2012-03-28 13:53:58