| Previous · Next | ||||||
| User | Message | |||||
|
secondlion
|
Date: 8/12/2005 2:51 pm · Subject: SQL with Javascript · Rating: 1
HI guys, I need to use a SQL command in a javascript. But I can't get it worked if I use a js variable inside ^SQL(); Something like: <script> var whatisname="My Name"; my_var='^SQL(select user from user_data where name=whatisname);'; </script> because the whatisname variable is changed often so I cannot put a constant value in ^SQL (); Anybody knows how to solve this problem, please help! Thanks in advance. --- (Edited at 6/17/2004 12:34 pm by secondlion) --- --- (Edited at 6/17/2004 12:35 pm by secondlion) --- |
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
secondlion
|
Date: 8/12/2005 2:51 pm · Subject: SQL with Javascript · Rating: 1
HI guys, I need to use a SQL command in a javascript. But I can't get it worked if I use a js variable inside ^SQL(); Something like: <script> var whatisname="My Name"; my_var='^SQL(select user from user_data where name=whatisname);'; </script> because the whatisname variable is changed often so I cannot put a constant value in ^SQL (); Anybody knows how to solve this problem, please help! Thanks in advance. --- (Edited at 6/17/2004 12:34 pm by secondlion) --- --- (Edited at 6/17/2004 12:35 pm by secondlion) --- |
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
jjrowan
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: 0
Use the SQL Report wobject.
In the Description section enter something like: Enter your name: Turn on the Preprocess macros on query button. In the query portion of the same form: select user from user_data where name=upper('^FormParam("myname");') That should get you some results. If you're having trouble with it turn on debugging to see whether your syntax is wrong or whether you have access problems. |
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
secondlion
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: -1
Thanks for replying but I am still confused. What does ^FormParam(); macro do? Suppost I don't use input from a form but from a javascript function. For example: fuction getUserInfo(username) document.write(^SQL(select value from user_data where ...);); </script> <A href=removed;>Click here to get this user information</a> What do I need to put behind the "where" condition? Please help! Thanks very much.
|
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
heilpern
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: -1
If I understand what you're trying to do, it cannot work. Macros are processed by the server, some time before a document is served to the remote client. Once that document is served, no more macro processing can happen (unless you reload the page). Javascript (in the normal context, which is how you are portreying things) is executed by the remote client as a result of being served a page. The javascript cannot request a macro be reprocessed for any purpose, as the server is already done serving that page (and does not allow for communications back to it regardless). I think you will need to rethink how to accomplish your goal here. |
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
secondlion
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: 1
Great information!!! Do you have any advices for me about other ways to accomplish the goal? I really appreciate it.
|
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
heilpern
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: -1
It's hard to make a suggestion on how you might proceed, without knowing just what it is you're trying to accomplish, but I will make a guess here. I am assuming you want to present information to the user based on tables of a database. This could be done without any javascript through use of a SQL Report Wobject, but I will assume further that you want some kind of dynamic handling of this data, hence your use of Javascript. The basic use of an SQL Report simply presents all the data in an html table. Using the report template however, you can do much more. The "normal" (most frequently used) templates here probably just present data in a slightly advanced table (custom formatting, links based on data, etc), but there's no requirement that this template build an html table at all. For example, you could create a template that builds initialization of a Javascript array with the results of your SQL Report. The general architecture of an SQL Report's template is:
Notice that each section is seperated with the ^-; macro. Your header could open up the javacript section, and perform any static initialization you want done. The body will be repeated once for each row of output, and could be used to initialize the elements of a two-dimentional javascript array. (There is a ^rownum; macro which can act as the first dimension.) Then the footer would close out this array initialization and follow up with whatever code you needed to tie everything together. |
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
zxp
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: -1
What value the ^ SQL(select value from user_data where ...) ; return ? I guess if the SQL macro return a string include some char such as ",', etc. or SQL macro return a LF,EOF char, the javascript will not run.
|
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
secondlion
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: 1
Thanks for your suggestions but I think I am not able to use the SQL template. May be I should tell you more about my goal. I have a data form. Customers will enter their information off the form and I want to be able to send an e-mail to them using a hyperlink which will include all the data they entered. So basicly, I dont have anything to do with SQL report template. I just need to pull out some needed information and put it into the MS Outlook Mail before sending it back to customers. Do you think I can have it done by some other ways? Thanks |
|||||
| Back to Top |
Rate [ | ]
|
|||||
|
jjrowan
|
Date: 8/12/2005 2:51 pm · Subject: Re: SQL with Javascript · Rating: 1
Use the article wobject. In the article use basic <form method="POST" action=/cgi-bin/yourperlscript.pl">
<input type="text" name="personsname" size="20"> <input type="text" name="emailaddress" size="30"> add your other stuff you want to record then <input type="submit" value="Send Data"> <input type="reset"> </form> In your PERL CGI read in the values from personname, emailaddress and your other fields. Then write an e-mail text in your /tmp directory and shell out to the OS to run sendmail -t the -t tells sendmail to take addressing info from the file. After you send the email and update your database with the information the user entered be sure you delete (unlink) the file you created in /tmp. |
|||||
| Back to Top |
Rate [ | ]
|
|||||