Page 1 of 1

Multiple WHEREs

Posted: Wed Aug 11, 2004 10:12 pm
by AliasBDI
I was hoping to have a query that would check for a WHERE = <URLvariable> and if nothing, then go to SETVARIABLE.

Here is my code:

Code: Select all

SELECT * FROM con_company WHERE active = '%s' ORDER BY company ASC
The variable will be either a 'Y' or 'N'. I want it to check for either, and if no URLvariable is passed, then use 'Y'. Any ideas?

Posted: Wed Aug 11, 2004 10:46 pm
by nigma
Here's some pseudocode that might help you plan things out:

Code: Select all

if ($urlvariable) {
  // urlvariable is set
  $where_val = $urlvariable;
} else {
  // urlvariable not set, use default value (Y)
  $where_val = 'Y';
}

$query_text = "SELECT * FROM con_company WHERE active = '$where_val' ORDER BY company ASC";

?>
Hope it helps

Posted: Wed Aug 11, 2004 10:46 pm
by feyd

Code: Select all

$sql = sprintf('SELECT * FROM con_company WHERE active = ''%s'' ORDER BY company ASC', (isset($_GET['URLvariable']) && ($_GET['URLvariable'] == 'Y' || $_GET['URLvariable'] == 'N')) ? $_GET['URLvariable'] : 'Y');

Posted: Wed Aug 11, 2004 10:56 pm
by AliasBDI
Not sure I'm doing it right, here is my code.... without any of your suggestions.

Code: Select all

$query_queryLIST = sprintf("SELECT * FROM con_company WHERE active = '%s' ORDER BY company ASC", $colname_queryLIST);

Posted: Wed Aug 11, 2004 11:51 pm
by nigma
Out of curiousity why are you using sprintf() ?

because

Posted: Wed Aug 11, 2004 11:56 pm
by AliasBDI
I'm using Macromedia DreamWeaver MX 2004. That is what it creates.

Posted: Fri Aug 13, 2004 7:11 pm
by Serberus
$query_queryLIST = 'SELECT *, IF (active = "Y" || ISNULL(active), "Y", "N") as activity FROM con_company ORDER BY activity, company ASC';

I can't test it because I don't have a similar table setup, does that work for ya?