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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:21:50+00:00 2026-05-28T19:21:50+00:00

I would like the users to choose which fields they want to see and

  • 0

I would like the users to choose which fields they want to see and which they do not want to see.

Table: Companies(cid, cname, state, project_manager, site_supervisor, elec_engg, mech_engg, hydraulics, …..)

Note: All the columns from project_manager to the last column have the value ‘Yes/No’

Lets say the user wants to find the companies that have Project managers and electrical engineers in NSW.

The Query will be:

Select cid, cname, project_manager, elec_engg  
from companies  
where state='NSW'  
    AND project_manager='Yes'  
    AND elec_engg ='Yes';

I was wondering how can I make this search dynamic. Displaying all job titles in a HTML form and having check boxes next to each job title and with search button. Something like below.

Query:

select cid, cname, (dynamic user input of columns) 
from companies  
where state="NSW"  
    AND Dynamic input column1 ='Yes'  
    and Dynamic input column2 ='Yes'  
    AND Dynamic input column3 ='Yes'.....  
    AND Dynamic input columnn ='Yes';
  • 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-28T19:21:50+00:00Added an answer on May 28, 2026 at 7:21 pm

    I’m assuming you’re just ANDing all the parameters together. If you can set the name for each HTML the elements in the form exactly what you expect for the column name this should work. When you get the post back (assuming search submits the form as a post), you can loop through the post values. I’d create an array of valid columns to check against as a whitelist to avoid ever having a broken query.

    Here’s an example using oldschool mysql escaping or you to get the idea, but I’d really use PDO with prepared statements to populate the values of the query. The key is to protect both your where parameters and values when dynamically creating SQL. Shoot me a message if you’re using PDO and would like to see that, but this will give you a place to start:

    $sql = 'SELECT cid, cname, project_manager, elec_engg FROM companies ';
    $whereClause =  null;   
    
    //whitelist of valid where clause parameters
    $validParams = array('site_supervisor', 'elec_engg', 'mech_engg', 'hydraulics');
    
    foreach($_POST as $key=>$value){
        if(array_search($key, $validParams)!==false){ //make sure you use !== and not !=
            if(empty($whereClause)){
                $whereClause = " WHERE ";
            }else{
              $whereClause .= " AND ";
            }
    
            //IMPORTANT: use whatever you're db needs to escape things or use prepare
            //statement replacement
            $whereClause .= "$key='".mysql_escape_string($value)."' "; 
        }
    }
    $sql = $sql.$whereClause;
    echo $sql;
    

    You can also add a loop check for just values of ‘Yes’ and exclude ‘No’ values…

    As noted below in a comment mysql_escape_string($value) is bad… no doubt, to do this correctly and safely with prepared statements and pdo you would change the code to:

    $sql = ‘SELECT cid, cname, project_manager, elec_engg FROM companies ‘;
    $whereClause = null;

    //whitelist of valid where clause parameters
    $validParams = array('site_supervisor', 'elec_engg', 'mech_engg', 'hydraulics');
    
    foreach($_POST as $key=>$value){
        if(array_search($key, $validParams)!==false){ //make sure you use !== and not !=
            if(empty($whereClause)){
                $whereClause = " WHERE ";
            }else{
              $whereClause .= " AND ";
            }
    
            //IMPORTANT: use whatever you're db needs to escape things or use prepare
            //statement replacement
            $whereClause .= " $key=:$key "; 
        }
    }
    $sql = $sql.$whereClause;
    $db = new PDO($someDsnString);  
    $statement = $db->prepare($sql);
    
    foreach($_POST as $key=>$value){
        if(array_search($key, $validParams)!==false){ //make sure you use !== and not !=
        $statement->bindValue(":$key", $_POST[$key]);
        }
    }       
    $statement->execute();
    $result = $statement->fetchAll();
    

    Both the prepared statements on the values and the whitelist on the parameter values will make this query safe.

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

Sidebar

Related Questions

I would like my users to select the columns of table they want to
I've developed a webservice and rightfully my users would like to see documentation. I'd
We have a project (Web/PHP) where we would like users to access their files,
I would like to enable users of my application to define a number of
I would like to allow users to call my ruby on rails app as
I would like to track users clicks on my website. For that purpose, I
I have a ASP.NET 3.5 web application and I would like to allow users
I know this isn't a programming question but I would really like the users
I'm new to the twitter API https://dev.twitter.com/docs/api and I would like to incentivize users
I would like to forward iphone users to a mobile version of my site

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.