Jump to content

[SOLVED] Complicated Select query


Clinton

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.