Make ASP Dynamic Web site with Dreamweaver MX 2004 (Voting system article)

Source: Internet
Author: User
Tags dsn insert connect odbc one table first row dreamweaver access
Dreamweaver| News | vote

Voting program source file: Click here to download the source file

  procedure description and voting system flow chart

Generally speaking, voting system can be divided into 3 modules: Ballot module, ballot processing module and result display module!

The voting system needs to record the choice of an item, usually in the database and then statistics the vote and display the results.

First give the ballot, the form object that the voter chooses, when the voter presses the voting button, the ballot processing module activates, the data that transmits to the server is processed, the server side first determines which item the user chooses, and then adds the value of the corresponding field to 1. In fact, the tables in the database where the voting results are saved are only one record, but the data needs to be constantly updated. Finally, the results show the module to show the voting results.

This tutorial explains the voting system for an evaluation of a film. There are 3 choices in this example, very good, general and very poor! And only one of the items can be selected.

File Description:

*vote.asp Polling Page
*result.asp Show Voting results
*add.asp ballot processing module, the voter selected on the polling page and press the voting button and submitted, the database is updated, and finally turned to result.asp

  Second, the design and establishment of the database

The database file Tvote.mdb has only one table tvote, the table has only one record, and the record corresponds to 3 fields, each of which holds an option for the number of votes. New table record initial value is 0, in order to facilitate the viewing effect, so first of all the records of the fields assigned initial!

  Third, establish the site and database connection

1. Set up the site! I won't tell you the detailed steps for setting up a site. Put up a picture and look down!!

Remind, don't forget to set up a virtual directory before setting up a site!

2. The database connection, here uses constructs the 0DBC the method to connect the database!

The DSN (data source name), which represents a collection of information that is used to connect an application to a database. The ODBC Data Source Manager uses this information to create a connection to the database!

Concrete steps: Start Control Panel-admin tools-Data Source (0DBC)-System dsn-"add"

Then in the open Create New Data Source dialog box, select Microsoft Access Driver (*.mdb) Click "Finish" to appear in the ODBC Microsoft Access Installation dialog box, give the name of the data source you want to create, and click "Select", Select the path to the database file you created! Click OK to see a new data source that we have just created in the ODBC data Source manager.

Then to Dreamweaver inside, open the site we just set up, casually open a file! Open the Database tab of the application panel, point "+", and select "Data source Name (DSN)"

Then in the Open dialog box to make the following settings, you can click the test to see if the database connection is successful!

  Iv. Voting System homepage Making

In fact, voters simply need to make a choice and do not need to add any action. You need to set the properties of the form and the form object on the polling page.

1. Make the following static page first

Note that the table in the page must be nested in a form (form) inside (I just started to learn ASP, are directly to get a table, the results of the N-time error)

2.form settings

Move the cursor over the form area, and click the form label below the window to select the form. Set the form property as follows

Click the Radio button property in the first row of the right column of the table to set the properties of the radio button in form. In its Properties panel, enter Rbresult in the radio button text box, which sets the name of the radio button to Rbresult, and enter Fgood in the selected value text box, which sets the value of the radio button. As shown in figure

The Value property entered is the same as a field name in the table Tvote in the database. The Fgood field in table Tvote saves the total number of voters who choose [very good] items, and after the voting button is pressed, the Fgood is outgoing as a radio button, linked to the field name in the database!

In the initial state option, select the Checked radio button, which is selected by default!

Also, follow these steps for the following 2 radio buttons!

The Name property of the following 2 radio buttons in the table is also set to Rbresult, which makes the Name property of the 3 radio buttons the same so that voters can only select one of them. Select the unchecked radio button in the initial state option, and in the selected value text box, enter Fmid, Fbad, and the other two fields in the table Tvote, vote. The ASP will do well!

  V. Making of the results page of the poll

Make a page

2. Defining a Recordset

Open the data [bindings] panel, click the [+] button, select the Recordset (query) menu item,

If the Simple Recordset dialog box appears, you should click Advanced ... button to go to the Advanced Recordset dialog box!

Enter Rsvote in the Name text box, select Connvote in the connection Drop-down list, and write "Select Fgood, Fmid, Fbad, (Fgood+fmid+fbad) as Vtotal, (Fgood/vtotal) as" In the SQL list box. Goodpercent, (fmid/vtotal) as Midppercent, (fbad/vtotal) as Badpercent
From Tvote "

3. Data binding

Place the cursor between "Someone voting", select the Vtotal field in the Bindings panel, and then click Insert to add the total number of voters to result. ASP page! Bind the other fields to the appropriate location in the same way

The last completed page as shown

4. The 3 Dynamic Data in the goodpercent/midpercent/badpercent of the recordset are the proportion of the total number of votes [very good] [generally] [very poor]. The values of these three dynamic data are decimal, and will be displayed as decimal when browsing, so convert him to percentages and keep 2 decimal places.

Select {Rsvote.goodpercent} in the first row of the table, and then in the Bindings panel, click the Drop-down triangle on the right side of the goodpercent (that is, the dropdown in the recordset format box), select [Percent]-[2 decimal places] in the menu that pops up.

The same method setting {rsvote.badpercent}{rsvote.midpercent}

5. Make the dynamic properties of the table

The diagram can be made using table nesting and dynamic properties of the table. If you nest a small table with only one row in the 2nd column of each row in the table, set the background color of this small table to red, set the width measurement unit of the small table to a percentage (relative to the width of the cell that holds him) depending on the number of voters, so that the diagram is made. The gray part can be seen as the total number of votes, and the red part can be seen as the number of options.

Create a representation of the proportion of [very good] votes in the total number of people. Place the cursor on the 2nd column of the first row and insert a table.

Set the background of the table to red. Select the small table, select the window]-[tag Inspector, open the Tags panel, and select Properties. Find the General]-width property, select him, and then a lightning button will appear next to him. Clicking the Lightning button pops up a Dynamic Data window. Select Goodpercent in the recordset in the Field list box, and then select the Percent-2 decimal places item in the Format Drop-down list. Click OK.

Repeat the steps above to insert a small table in line second to third. Only when setting dynamic properties, you must select Midpercent in the recordset in the list box of the Dynamic Data window. Badpercent Items
All right, result. The ASP page is also here to be made. Can preview the next look at the Oh!

  VI. Update page add.asp

We vote on the polling page. When you set the Action property of a form in ASP, the file that has the corresponding action set is Add. asp!

1. Create a new dynamic page asp VBScript file

Here you can make a turn to result. ASP's Links!

2. Binding-command (stored procedure)

Since the voting system mainly records the number of votes for each option, this step is not to read the database or insert a record into the database, but rather to modify the value of a field in the database's table vote. To be exact, the data for a field in a table is vote, so you must select the command (stored procedure) menu item to be customized in a simple SQL language!

Click the + Select command (stored procedure) of the binding panel to set the diagram

In vote. When setting values in an ASP page but selecting the properties of a button, the value of the 3 radio button value properties has been set to 3 field names in the table vote, so the Request.Form ("Rbresult") value must be a field name for the table vote. So the meaning of this SQL statement is to make a field add 1, that is, write down a voter in the corresponding field!

* Note: In the actual operation, be sure to remove the [SQL] where the *

All right, so far, the file for this voting system is all done!

Send a final preview of the effect look down!

  Vii. production focus and related skills

To make a voting system, you first need to understand the mechanism of the voting system, the various webpage files that the voting system needs to build, and the steps to make these files. The main production technology are: voting system, the name of the radio button and the setting of the value attribute, the ability to store the values of radio buttons, the use of computational fields in SQL, the design techniques of the scale diagram and the formatting of dynamic Data formats, and so on.

But in testing the simple voting system described above, we found that in the voting system, voters can vote indefinitely, making cheating easy to happen! So how do you find a way to get every voter to vote only once to reduce the likelihood of a string of votes? We can consider this problem first, and I will send this tutorial in a few days!

Finally done, have the wrong place also please the moderator elder brother help point out!!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.