Try using something a little different:
if ($surname_all){ //checks to see if the variable is set
$surname_query = "WHERE surname between $surname_from and $surname_to";
} else {
$surname_query = "";
}
-----Original Message-----
From: Craig Shepherd [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 04, 2002 10:55 AM
To: [EMAIL PROTECTED]
Subject: Dynamic SQL
Using UltraDev 4 with Phakt 1.2.1, linking to a MySQL server 3.22.23
I want to develop a SQL SELECT query where I can vary what customers are
listed depending on the value of various form fields.
For example if the check box surname_all is ticked then all customers are
displayed if not then it displays all customers where the surname lies
between surname_from to surname_to.
I couldn't find an appropriate way of handling this in MySQL directly so my
aim was to determine the SQL portion outside the query and then append it to
the query:
if ($surname_all == -1){
$surname_query = "WHERE surname between $surname_from and $surname_to";
} else {
$surname_query = "";
}
NB - If $surname_all = -1 then it has been ticked.
And then I would declare my SQL statement as
"SELECT * from customers".$surname_query
UltraDev doesn't like this and so I would appreciate any help in either a
better way to code it in UltraDev or a SQL statement that would achieve the
same aim.
Thanks for your help
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php