Jump to content

Recommended Posts

I didn't think it was that complicated but everytime I add another variable it seems to not work. This time it's the state variable. I added it and my query is pretending like it's not there and displaying the rest of the result. ANy ideas?

 

$sql = "SELECT * FROM $tbl_name WHERE dtype = '$dtype' OR dtypewc = '$dtype' AND dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor' AND state = '$state' ORDER BY jpted LIMIT $start, $limit";

Link to comment
https://forums.phpfreaks.com/topic/139694-solved-complicated-select-query/
Share on other sites

Thanks Gevans, that worked. Now one more question. If the state variable hasn't been selected I want them to be able to view all states. Do I have to do an if isset statement or can I use a * or a wildcard variable of somesort? I've tried both * and % to no avail.

 

 

$state_where = "";
if(!empty($state)){
    $state_where = " AND state = {$state}";
}

$sql = "SELECT * FROM $tbl_name WHERE dtype = '$dtype' OR dtypewc = '$dtype' AND dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor' {$state_where} ORDER BY jpted LIMIT $start, $limit";

 

Thats how I would go about it.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.