Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed Aug 11, 2004 10:12 pm
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?
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Wed Aug 11, 2004 10:46 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 11, 2004 10:46 pm
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');
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed Aug 11, 2004 10:56 pm
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);
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Wed Aug 11, 2004 11:51 pm
Out of curiousity why are you using sprintf() ?
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed Aug 11, 2004 11:56 pm
I'm using Macromedia DreamWeaver MX 2004. That is what it creates.
Serberus
Forum Newbie
Posts: 5 Joined: Fri Aug 13, 2004 6:31 pm
Location: Hertfordshire, UK
Post
by Serberus » Fri Aug 13, 2004 7:11 pm
$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?