Now we have the database, lets make a website for it. First lets make a page that lets people search the database.
<form method = "post" action = "results.cfm"> <h1>Search For Friends</h1> <select name = "Sex"> <option value = "male">Male <option value = "female">Female </select> <input type = "Submit" value = "Submit"> </form>
We have our simple search page, now we need the results page:
<CFQUERY DATASOURCE = "Friends" NAME = "MAIN"> SELECT FirstName, LastName, Age, FriendID FROM Friends Where Sex LIKE '#sex#' </CFQUERY> <div align = "center"> <b>You Found the Following Friends</b><br> <table border = "1"> <tr> <td> First Name </td> <td> Last Name </td> <td> Age </td> <td> More Info </td> </tr> <CFOUTPUT QUERY = "MAIN"> <tr> <td> #FirstName# </td> <td> #LastName# </td> <td> #Age# </td> <td> <a href = "info.cfm?ID=#FriendID#>Click Here!</a> </td> </tr> </CFOUTPUT> </table> </div>
Now lets examine the above. As you can see to perform a ColdFusion Query you just fill in the CFQUERY tags with your SQL statement and you're good to go. Any part of the SQL statement can be substituted with a variable passed from a previous page as I did with the sex variable. Then notice the CFOUTPUT tags have a query argument, this tells it that it is drawing info from a query and also sometimes you will use multiple queries on one page, this tells it which query to use.