Search XML using combo box for Title & Description

armychick_2001

New Member
hi im trying to search an XML document using a combo box so the user can search in either description or title. I have loaded the XML file to the page that i wish to display the searches on. The search box its self is attached to a top.php document. I have tried to store the variable and apply them to a XML search string. i get the following errors but am unsure how to proceed.Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Invalid expression in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/web/searchResults.php on line 19Warning: Invalid argument supplied for foreach() in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/web/searchResults.php on line 22searchResults.php\[code\] <?phpinclude "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= http://stackoverflow.com/"{$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 = "http://stackoverflow.com/questions/10398710/Holiday Search..."> <select name = "searchOption"> <option value = "http://stackoverflow.com/questions/10398710/null" selected>(select)</option> <option value = "http://stackoverflow.com/questions/10398710/title">Title</option> <option value = "http://stackoverflow.com/questions/10398710/description">Description</option> </select> <input type = "submit" name = "search" value = "http://stackoverflow.com/questions/10398710/Search"> </form> \[/code\]
 
Back
Top