Exforsys
+ Reply to Thread
Results 1 to 3 of 3

how do i write a query in coldfusion?

This is a discussion on how do i write a query in coldfusion? within the Coldfusion forums, part of the Programming Talk category; how do i write a query in coldfusion?...

  1. #1
    gogbpackrs2 is offline Junior Member Array
    Join Date
    Mar 2007
    Answers
    1

    how do i write a query in coldfusion?

    how do i write a query in coldfusion?


  2. #2
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128
    The following steps would help you to search and display the query results:
    Create a Cold Fusion page with the following content:
    <html>
    <head>
    <title>Searching a collection</title>
    </head>
    <body>

    <h2>Searching a collection</h2>

    <form method="post" action="collection_db_results.cfm">
    <p>Collection name: <input type="text" name="collname" size="30"
    maxLength="30"></p>

    <p>Enter search term(s) in the box below. You can use AND, OR, NOT,
    and parentheses. Surround an exact phrase with quotation marks.</p>
    <p><input type="text" name="criteria" size="50" maxLength="50">
    </p>
    <p><input type="submit" value="Search"></p>
    </form>

    </body>
    </html>

    Save the file as collection_db_search_form.cfm in the myapps directory under the web_root.
    This file is similar to collection_search_form.cfm, except the form uses collection_db_results.cfm, which you create in the next step, as its action page.

    Create another Cold Fusion page with the following content:
    <html>
    <head>
    <title>Search Results</title>
    </head>

    <body>

    <cfsearch
    collection="#Form.collname#"
    name="getEmps"
    criteria="#Form.Criteria#"
    maxrows = "100">

    <!--- Output the record set. --->
    <cfoutput>
    Your search returned #getEmps.RecordCount# file(s).
    </cfoutput>

    <cfoutput query="getEmps">
    <p><table>
    <tr><td>Title: </td><td>#Title#</td></tr>
    <tr><td>Score: </td><td>#Score#</td></tr>
    <tr><td>Key: </td><td>#Key#</td></tr>
    <tr><td>Summary: </td><td>#Summary#</td></tr>
    <tr><td>Custom 1:</td><td>#Custom1#</td></tr>
    <tr><td>Column list: </td><td>#ColumnList#</td></tr>
    </table></p>

    </cfoutput>
    </body>
    </html>

    Save the file as collection_db_results.cfm in the myapps directory under the web_root.
    View collection_db_search_form.cfm in the web browser and enter the name of the collection and search terms.


  3. #3
    rameshuddaraju is offline Junior Member Array
    Join Date
    Oct 2006
    Answers
    3

    Writing a query in ColdFusion

    Quote Originally Posted by gogbpackrs2 View Post
    how do i write a query in coldfusion?
    By using coldfusion cfquery

    Example

    Your_DataSourceName : DSn name we created in Coldfusion server. which refers to your database.


    <cfquery name="AnyName" datasource="Your_DataSourceName">

    select empno,ename,sal from employee

    </cfquery>

    To display data from the above query

    <table>
    <cfoutput query="AnyName">

    <tr><td> #empno# </td><td>#ename#</td><td>#sal#</td></tr>

    </cfoutput>

    </table>


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...