Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:31:19+00:00 2026-05-31T22:31:19+00:00

At current i have an index page which shows values from an XML page

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:31:20+00:00Added an answer on May 31, 2026 at 10:31 pm

    Yes it is, you could add another variable to your form to check the function you have to show, something like that:

    <?php
    // create an instance
    $holidayDoc = simplexml_load_file('holidays.xml');
    
    $resultTable = "";
    
    switch (@$_POST['action']){
        case "Search":
    
            $txtSearch = $_POST['txtSearch'];
        $resultTable .= "Showing Results for <strong>$txtSearch</strong><br />";
    
            // 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
            $resultTable .= "<table border=\"0\">\n";
    
            foreach ($holidays as $holiday) 
            {
                $resultTable .= "<tr>\n";
                $resultTable .= "<td><a href=\"{$holiday->link}\">{$holiday->title}</a></td>";
                $resultTable .= "<td>{$holiday->description}</td>";
                $resultTable .= "<td>{$holiday->pubDate}</td>";
                $resultTable .= "<td><input type=\"checkbox\" name=\"saveCB\" value=\"3\"/></td>";
                $resultTable .= "</tr>\n";
            }
            $resultTable .= "</table>\n";
    
            break;
    
        default: // this means the home page, as is, without the query into XML file
            $resultTable .= "<table border=\"1\">";// draw a table and column headers
    
            // iterate through the item nodes displaying the contents
            foreach ($holidayDoc->channel->item as $holiday) {
                $resultTable .=  "<tr><td><a href=\"{$holiday->link}\">{$holiday->title}</a>" . "<br />" . 
                "{$holiday->pubDate}" . "<br />" . 
                "{$holiday->description}</td>" . "<br />" . 
                "</tr>";
            }
            $resultTable .= "</table>";
        break;
        }
    
    ?>
    
    <form name="search" method="POST" action=#">
        <input name="txtSearch" type="text" id="txtSearch" size="30"/>
        <input type="submit" value="Search" name="action" />
    </form>
    
    <?=$resultTable ?> <!-- finally show the result table -->
    

    I hope this useful!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an index page for listing products. From this page I would like
I would like to have a My_Events page, which only display events that current
I have current a developed app which I am going to submit in just
I have the current PHP: $thisarray[] = #000; SetProfileField('usercss', $USER->id, implode(',',$thisarray)); Which writes #000
I have three current thoughts on how to do this: re-implement AuthenticationService, which uses
Alright, here is my problem i'm trying to solve. I have an index page
I have created an HTML page which uses simple CSS (no javascript) for menu
The first question is how to run a function using the URL, I have
This is the first project by me which is using MongoDB. I have hosted
I have an application using JSF, which has a navigation bug. The homepage, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.