Forums
This topic is locked
Dynamic SQL
Posted 04 Mar 2002 16:59:06
1
has voted
04 Mar 2002 16:59:06 Craig Shepherd posted:
Using UltraDev 4 with Phakt 1.2.1, linking to a MySQL server 3.22.23I 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
Replies
Replied 05 Mar 2002 02:24:16
05 Mar 2002 02:24:16 Tim Green replied:
Unfortunately when you get into the realms of this kind of SQL query you soon run into issues because of the way that UltraDev works, and unfortunately there isn't a lot that can be done.
This kind of SQL Query usually means that you have to hand code the database interactions completely, so what you might want to do is to design the whole of your page etc using a standard recordset, and then make the changes to the recordset when the page is finished.
Hope this helps
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
This kind of SQL Query usually means that you have to hand code the database interactions completely, so what you might want to do is to design the whole of your page etc using a standard recordset, and then make the changes to the recordset when the page is finished.
Hope this helps
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 05 Mar 2002 10:46:58
05 Mar 2002 10:46:58 Craig Shepherd replied:
Thaks for your input. I had sort of come to that conclusion but I was hoping that some guru out there would have an answer.
Might it be possible to use some kind of IF statement within the SQL query to achieve the same thing?
Thanks again
Craig Shepherd
Edited by - king_mob on 05 Mar 2002 10:47:27
Might it be possible to use some kind of IF statement within the SQL query to achieve the same thing?
Thanks again
Craig Shepherd
Edited by - king_mob on 05 Mar 2002 10:47:27
Replied 07 Mar 2002 21:20:12
07 Mar 2002 21:20:12 Tim Green replied:
You could use an IF statement in your SQL, but again, that is advanced SQL useage, and it still won't conform to the UltraDev way of doing things. Unfortunately this will mean that you'll still end up having to hand code sections of your page....
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 08 Mar 2002 10:18:45
08 Mar 2002 10:18:45 Craig Shepherd replied:
Thanks again for your input. I have a working version now using a series of PHP if statements to build a SQL query.
Pity that there's no way to incorporate this into the UD functionality it would have been a great help.
Craig Shepherd
Pity that there's no way to incorporate this into the UD functionality it would have been a great help.
Craig Shepherd