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

  • Home
  • SEARCH
  • 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 9012179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:55:50+00:00 2026-06-16T02:55:50+00:00

I am having trouble figuring out how to work an if statement into my

  • 0

I am having trouble figuring out how to work an if statement into my PHP containing a MySQL Query. Here’s what I have so far (it’s unfinished):

$industry = $_GET['industry'];
$location = $_GET['location'];
$position = $_GET['position'];
$region = $_GET['region'];

if($industry=="any"){

}

if($location=="any"){

}

if($position=="any"){

}

if($region=="any"){

}

$sql_cat = "
SELECT *
FROM jobs
WHERE industry_cat='$industry' && location_cat='$location' && position_cat='$position' && region_cat='$region'
ORDER BY id DESC
";
$result_cat = $mysqli->query($sql_cat);
$num_rows_cat = mysqli_num_rows($result_cat);

Basically, what I’m trying to say is that if any of the variables are set to ‘any’ then I want those variables to represent all the possibilities (there’s like five possibilites in the form for each variable). I figured I’d use arrays in the where clause (like WHERE industry IN ($industry)) but then it wouldn’t work if someone actually did pick a variable.

I may be a little off track but am having trouble wrapping my mind around it. Any help would be greatly appreciated. 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-06-16T02:55:53+00:00Added an answer on June 16, 2026 at 2:55 am

    If I did not misunderstand your question, I would do this.

    $sql = "SELECT * FROM jobs WHERE 1";
    if($industry !== "any"){
        $sql .= " AND industry_cat = '$industry'"
    }
    if($location !== "any"){
        $sql .= " AND location_cat = '$location'"
    }
    if($position !== "any"){
        $sql .= " AND position_cat = '$position'"
    }
    if($region !== "any"){
        $sql .= " AND region_cat = '$region'"
    }
    $sql .= " ORDER BY id DESC"
    $result = $mysqli->query($sql);
    

    You can remove single quote around the variables in the query if you are sure they are integer.

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

Sidebar

Related Questions

I'm having trouble figuring out why this query does not work. Names have been
I'm having trouble figuring out how to work with word ranges. I have picture
I'm having trouble figuring out how to get this simple operation to work. LineItem
I am having trouble figuring out how to get Facebook insights into from my
Hey I'm having trouble figuring out how to get my template header to work.
I'm having some trouble figuring out how to do this. I want to have
I'm having trouble figuring out how to work with the Datatables plugin for jQuery
I'll try this again. I'm having trouble figuring out how to work with the
I'm having trouble figuring out how the in-app billing process is supposed to work
I'm building a database for my work and I'm having trouble figuring out how

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.