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 9171005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:06:16+00:00 2026-06-17T16:06:16+00:00

I’m finding it hard to get my head around the logic around this issue

  • 0

I’m finding it hard to get my head around the logic around this issue I’m having.

Currently, I have a search.html page that on submit goes to Results.php. There is then some code that searches the mysql for whatever was inputted into the search page.

Now, How would I go about having the search and the results on the same page? How would i return the variable from the search page? For example before I was using;

$search_term = $_POST['name'];

How would I get the ‘name’ variable if its on the same page?

EDIT: Second issue

I have the code working that many of you answered with, thank you very much! I’ve now come to my second problem. I have two inputs a textbox for the search query and then a dropdown box for a subject to search.

Then user then presses submit and the db is searched, this all works fine. I now want to create another dropdown box so the user can sort the provided results in a matter that they see fitting, for example price high to low etc.

I have the HTML code already done but as you can imagine, the second I press submit its reloading the page and as it doesn’t know what the user has previously searched it exits the php and acts as if its a fresh page load.

URL: http://helios.hud.ac.uk/u0862025/db/test.php

Play around with it, press submit to lift all products in the database.

  • 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-06-17T16:06:17+00:00Added an answer on June 17, 2026 at 4:06 pm

    You could just make the whole thing in one file. This is crude and totally incomplete, but something like this –

    <?php
    $results = array();
    $term = "";
    
    if(isset($_POST['name']))
    {
        $term = $_POST['name'];
        $order_by = "";
    
        if(isset($_POST['order'])
        {
            switch($_POST['order'])
            {
                case "price-high-low":
                    $order_by = "ORDER BY `price` DESC";
                break;
                case "name":
                    $order_by = "ORDER BY `name` ASC";
                break;
                default:
                    $order_by = "ORDER BY `id` DESC";
                break;
            }
        }
    
        $sql = "SELECT * FROM `your_table` WHERE `name` LIKE '%". sanitized($_POST['name']) ."%' $order_by";
    
        //run query and assign the results to a variable, like $results
    }
    ?>
    <form action="" method="post">
        <input type="text" name="name" value="<?php echo $term; ?>"><br>
        <?php if(!empty($results)): ?>
        <select name="order">
            <option value="price-high-low">Price: High to Low</option>
            <option value="name">Name</option>
        </select>
        <?php endif; ?>
        <input type="submit" value="submit">
    </form>
    
    <?php if(!empty($results)): ?>
    Results for term: <?php echo $term; ?><br>
    <?php foreach($results AS $res): ?>
        <?php echo $res['name']; ?><br>
    <?php endforeach; ?>
    <?php endif; ?>
    

    Of course this is very crude and assumes many things. Like that your results are an array, for one. That your results have a key called name, etc.

    But as you asked, this is all on one page and that’s the basic idea.

    feel free to ask any questions and I may update as needed.

    ** UPDATE 1 **
    I updated this example to consider a dropdown that only shows after a result is made. It will re-submit the form with an added order parameter. This example does not consider pagination and makes the assumption that you have a sanitize function that cleans the input. Obviously you should be using mysqli or PDO as they will both offer solutions for this. Do NOT rely on mysql_ functions like mysql_real_escape_string. All mysql_ is deprecated and should not be used anymore.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.