2012-05-01 41 views
1

嗨即時嘗試使用組合框搜索XML文檔,以便用戶可以搜索描述或標題。我已將XML文件加載到希望顯示搜索的頁面上。其自身的搜索框附加到一個top.php文檔。我試圖存儲變量並將它們應用於XML搜索字符串。我收到以下錯誤,但不確定如何繼續。標題和說明使用組合框搜索XML

警告:的SimpleXMLElement ::的xpath()[simplexmlelement.xpath]:行中/var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/web/searchResults.php表達式無效19

警告:的foreach()在/var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/web/searchResults.php供給線路22上

SearchResult所無效的參數.php

<?php 
include "top.php"; 
$holidaysXML = simplexml_load_file('holidays.xml'); 



if(isset($_POST["txtSearch"]) && $_POST["txtSearch"] != "Holiday Search..." && $_POST["txtSearch"] !="") 
    { 
     $txtSearch = $_POST["txtSearch"]; 
     $searchOption = $_POST["searchOption"]; 
     if($_POST["searchOption"] != "null") 
     { 
      $searchOption = $_POST["searchOption"]; 
      $searchedResult = "Search results for \"$txtSearch\" in $searchOption"; 
      $resultsHoliday = "channel/item [contains($searchOption, \"$txtSearch\")]"; 
     } 

    } 
    $allHolidays = $holidaysXML->xpath($resultsHoliday); 


      foreach ($allHolidays as $currentHoliday) 
      { 

         echo "<a href= \"{$currentHoliday->link}\" style=\"font-weight:normal\" target=\"_blank\">{$currentHoliday->title}</a><br>"; 
         echo "{$currentHoliday->pubDate}<br>"; 
         echo "{$currentHoliday->description}"; 
      } 

This is where the information is gathered from the user on top.php 

    <form action = "searchResults.php" method = "post"> 
        <input type = "text" name = "txtSearch" value = "Holiday Search..."> 
         <select name = "searchOption"> 
         <option value = "null" selected>(select)</option> 
         <option value = "title">Title</option> 
         <option value = "description">Description</option> 
         </select> 
        <input type = "submit" name = "search" value = "Search"> 
       </form>    

回答

1

您看到的第一個問題是由於。

Holidays = $holidaysXML->xpath($searchedResult); 

應該是:

Holidays = $holidaysXML->xpath($resultsHoliday); 

$resultsHoliday是握着你的XPath查詢變量。

+0

錯過了我進行更改,看看會發生什麼 –