Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Using variables in SELECT FROM WHERE
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using variables in SELECT FROM WHERE

 Post Reply Post Reply Page  <12
Author
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 2:39pm
the onlyt way i can see is to set another vieriable for each one you want to show within the above if /else if statement.



like strdisplayCell1 and strDisplayCell2 etc.. then add within the table row to response.write strDisplayCell1 under the last collumn and StrDisplayCell2 under the first collumn..

and within the if statement you set the value of the field.

Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 3:04pm

Sorry, you lost me on that one. Is there no way to midify the sytax to display the value (val(variable) or something) versus the name of the vaiable?

Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 3:10pm
sorry about that


the best way i think of doing it is

when you set the name of the veriable veriablename = "rsObject("First")"

set another veriable holding rsObject("First") 's value

then when you response.write the row use the new veriable which will write the object/fields value
Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 3:54pm
Sorry, I guess I'm a little slow. If I'm trying to use the variable to both display the value and set the column position in the table how would I use the second variable and keep it dynamic?
 
strSearchby is determined by a radio button selection. It also sets which values are in columns 1, 2 and 3.
 
    If strSearchby = "first" Then
      strDesc1 = "First"
      strDesc2 = "Last"
      strDesc3 = "Ext"
      strField1 = "rsObject('first')"
      strField2 = "rsObject('last')"
      strField3 = "rsObject('ext')"
        ElseIf strSearchby = "last" Then
          strDesc1 = "Last"
          strDesc2 = "First"
          strDesc3 = "Ext"
          strField1 = "rsObject('last')"
          strField2 = "rsObject('first')"
          strField3 = "rsObject('ext')"
        ElseIf strSearchby = "ext" Then
          strDesc1 = "Ext"
          strDesc2 = "First"
          strDesc3 = "Last"
          strField1 = "rsObject('ext')"
          strField2 = "rsObject('first')"
          strField3 = "rsObject('last')"
    End If
 
'Display recordsets in table
      Response.Write "<TR>"
      Response.Write "<TD><FONT COLOR='#000066' FACE='arial' SIZE='2'>" & strField1 & "</FONT></TD>"
      Response.Write "<TD><FONT COLOR='#000066' FACE='arial' SIZE='2'>" & strField2 & "</FONT></TD>"
      Response.Write "<TD><FONT COLOR='#000066' FACE='arial' SIZE='2'>" & strField3 & "</FONT></TD>"
      Response.Write "<TD>" & "<FONT COLOR='#000066' FACE='arial' SIZE='2'>" & rsObject("dept") & "</FONT>" & "</TD>"
      Response.Write "<TD>" & "<FONT COLOR='#000066' FACE='arial' SIZE='2'>" & rsObject("loc") & "</FONT>" & "</TD>"
      Response.Write "</TR>"
 
If I follow you correctly, you are saying to set a second variable to hold the value of rsObject("x") but still need to plug that back into the table. At that point it's no longer changing based on the radio button selection and I could use rsObject("x") as in the last two columns.
 
Am I missunderstanding you?
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 4:10pm
yok reading what you are doing .., within the loop of each record you need to get the veriable for the last 2 cells

DEPT and LOC.

the only way really is set another if statement within the loop/next for each record and check what the last 2 cells should contain

so have another If statement like the above  but set a temp veriable to the correct fields from the database

then  response .write that veriable within the cells. and re do that for every records

Quote
f I follow you correctly, you are saying to set a second variable to hold the value of rsObject("x") but still need to plug that back into the table. At that point it's no longer changing based on the radio button selection and I could use rsObject("x") as in the last two columns.


that is what im referring to.. do an if statement on this within the loop/next sequence for each records. its the only way i can think really of doing so
Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 5:14pm
I really appreciate your help dj. I'll probably rethink my overall approach. It seemed like a good idea at the time. One thing I'm still perplexed with? Why I can use rsObject("x") in the table:
 
Response.Write "<TD>" & "<FONT COLOR='#000066' FACE='arial' SIZE='2'>" & rsObject("dept") & "</FONT>" & "</TD>"
and have it plug in the appropriate value but I can set something up that with use the -value- of strFieldx (whick would be rsObject("x")) and have it work the same way and be supported by the same loop.
 
I'm pretty new at this and I'm wondering if I'm getting the capabilities/sytax of SQL and VBScript confused.
 
Can you explain why I can't do this? I can see the logic I'm after but I'm still too green to know why I can't do it. In this case I beleive it would help me to understand why I can't.
 
Either way, thank you very much dj. 
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 26 March 2005 at 10:14am
hi again, no problem with helping.

im not 100% sure what you said above but.

to show the value of a field within a database you use response.write (rsObject("Fieldname"))

or <%= rsObject("FieldName") %>

or you can set a veriable to hold the value

strValue = rsObject("FieldName")

a website that may help explain a few things is www.devguru.com

it shows all aspects of asp/VB and gives examples etc.

i hope that helps.

just incase.. what is the section for . i may be able to advise on a way
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.