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のオブジェクト 警告:行65のforeach()に無効な引数が指定されています 通知:未定義の変数:行77のアクション –
申し訳ありません、ここで修正する必要があります:
他のエラーは奇妙で、すべての変数は初期化されていないようですが、行番号は正しくありません。 – Gian私は変数を確認してください$ holidayDocと$ holiday、私は、申し訳ありませんが添付コードを変更します – Gian