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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:15:34+00:00 2026-05-26T04:15:34+00:00

This will hopefully be an easy one, but I’m lacking the skills! <select name=search_category

  • 0

This will hopefully be an easy one, but I’m lacking the skills!

                                <select name="search_category"  id="select1" >
<option value="">By Category</option>
 <?php if (!empty($_POST['search_category'])) { ?>
 <option value="<?php echo $_POST['search_category']; ?>" selected="selected"><?php echo $_POST['search_category']; ?></option>
<?php }?>
  <?php foreach($categoriesListt as $row) : ?>

  <option value="<?php echo $row->id; ?>"><?php echo $row->name; ?></option>

                                      <?php endforeach; ?>
                                </select>

The above is one of many select in a search module. It returns a dynamic list of options from a query higher up in my page. My goal is to have the option last searched pre-selected. Everything works as intended, but my problem is minimal really; the value of the posted search category is an ID($row->id. What I am hoping to do is use the associated $row->name for display, but keep the id for value so my search function still works.

In other words, I’m hoping to do something like:

<?php echo $row->name;  WHERE ID = $_POST['search_category']

Is there an easy way to do that in the above code, or will I need to add a special query at the top of my page, fetching the individual row name that matches the posted id?

Thanks!

EDIT: To simplify, I already have a query that returns row->id and row->name, which I use in a foreach loop to populate my option values and names. I simply need a way, or a line that I can add to my query to also get the value of the row->name that matches the POSTED id.

  • 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-26T04:15:35+00:00Added an answer on May 26, 2026 at 4:15 am

    i would write a short function which gives this functionality even for others applications.
    just like

    <?php 
    
        function($id, $table) {
    
            select ... etc
    
        }
    ?>
    

    For security Reasons I would suggest to use Prepared Statements or mysql_escape

    Hope i could help

    Perhaps

    SELCET('id', 'name' FROM yourTable WHERE 'name' = $_POST['ID']) 
    

    you mean something like this or would you select the dropdown option

    <?php foreach($categoriesListt as $row) : ?> 
        <option value="<?php echo $row->id; ?>"
              <?php if($row->name == $_POST['search_category']) : ?>
                   selected="selected"<?php } ?>>
            <?php echo $row->name; ?>
        </option> 
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this will be an easy one to answer. I created a class in
Hopefully this will be an easy one to answer. I am working on a
Hi hopefully this will be an easy one. I need to implement the classic
Hopefully this will be an easy one for anyone with any Django experience. I'm
This will hopefully be an easy one. I have an F# project (latest F#
Sorry for the rubbish title but hopefully this will explain: Given the table name
hopefully this will be an easy answer for some of you CSS veterans out
Hopefully this explanation will make sense, but what is the best way (if it
This will be a bit subjective, I'm afraid, but I'd value the advice of
Hopefully this will be an easy question! I have two tables, a 'client(s)' table

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.