At current i have an index page which shows values from an XML page using simpleXML. And a search function which prints to another page, what i want to do is to refresh the front page to show only the search results when the button is clicked.
index page.
<?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>";
?>
I then have my searchProcessDescription.php page
<?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";
?>
Is there a simple way to add this process to the index page and for the page to refresh when the search button is clicked?
Thanks
Yes it is, you could add another variable to your form to check the function you have to show, something like that:
I hope this useful!