Review / SQL:SELECT; CFQUERY; CFOUTPUT
Subtitles of the Movie
So here we have our form and we want this data to be dynamic. I want to be able to through a web form later on be able to change names of any of these towns or whatever. This could be anything, doesn't necessarily have to be our village ID. Let's access our database with a 'cfquery' command and we are going to name this query q_village_ID: q for because it's a query, and we are looking for the village ID. And then we have to access the database, and I will tell you later on how you set this up, but for now just consider this - the name of the database as the sever sees it is called 'business'. It's not what its file name is, we've created a pipe in the Cold Fusion server called business, and that pipe goes to the Access file. You will see that later on. If you look at the menu item for this CD, you will see one of them that says setting up a database on Cold Fusion server. So now we want to actually throw in SQL commands, and hopefully you know a little bit about SQL. It's very important if you are going to be developing in Cold Fusion; it's not a very hard language at all, and I recommend that you pick up a book on it if you want to get advanced But it's very simple, and we can do very simple stuff right now. Select everything from the village table, select all from village that's it. Now what does all (*) mean. Well, let's take a look at our database. Let's look at the village table. So now we are saying select all from village - what is in village? Well in village is village ID and village name. So it's going to pull out five records with 2 fields each. I am going to have five iterations of village ID and village name. So village ID and village name, remember that. Right now, we go down into our form, and in the portion of the form where we see the repetition and where we see the need to pull something from a database. I am going to put in cfoutput tag. I am going to take one of my option tags here that I am going to repeat and get rid of the rest. And in here, I put in village_ID, and then here I put in village name [villagename]. And that's it, cfoutput. Oh, that's not it. I have to add one thing, cfoutput and the query is q_village_ID. cfoutput is required - you have to grab, anytime you are going to use any Cold Fusion variables of which these are Cold Fusion variables, you have to wrap them in the cfoutput tag, or they will shop up literally as pound [#], what ever the variable name is pound. If you want these to be replaced with their values, it has to be in an output tag. But if you are pulling from a specific query, because you could have 5, 10, 20 queries in your Cold Fusion template, the server is not going to know where you are pulling this from. Because potentially, you could have 5 different queries, each slightly different. You could say select everything from village where you know the first letter is 'T', in which case you would have different results. So we have to say we want an output and have all the variables turned into their values when they are being put, sent to the browser, but we want to tie this particular output to the query q_village_ID. So the results of this are, we pull all the records out from village, table village in the database, and we know that there are 2 fields in there, village_ID and villagename. cfoutput will loop the number of times, as there are records returned from this query. So there are 5 records in there, so this will run 5 times, so we will have 5 options. We will have the village_ID number, which is in the database which is 1, 2, 3 or 5, and the villagename which is whatever the name is. Let's save this, go back over here, refresh and we have an error. Oh, I put in the wrong thing, its not dbname, it's datasource. Save it, run it and there we go - and there they are. Isn't that neat? We will try a variation on this in the next one. we go - and there they are. Isn't that neat? We will try a variation on this in the next one.
Tutorial Information
| Course: | Macromedia ColdFusion |
| Author: | Mike Muller |
| SKU: | 33287 |
| ISBN: | 1930519656 |
| Release Date: | 2001-12-19 |
| Duration: | 8 hrs / 86 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 