Checkboxes The three databases below are checkbox sets The

Document Sample
Checkboxes The three databases below are checkbox sets The Powered By Docstoc
					Checkboxes

The three databases below are checkbox sets. The first uses y,n values, the second
and third spell out their responses. Let's look what happens with y,n, then with spelled
out values although we'll still set up y,n in Dreamweaver, then with values where we
also spell out every opportunity to offer a value. We know there won't be problems with
inserting data into the database. We want to fool around with how the data outputs to
users.

Another issue is that we want to be able to either have the three tables separate for
user input/output, or combine them. If we combine, we need to go to the advanced
options at insert record. Let's use these three tables to do several combinations of
forms.

First. ENUM and SET as datatypes. We use ENUM and SET when we give values to
checkboxes and radio buttons, the values are the only choice for users. That's different
than textboxes where the user adds their own choice. ENUM allows the user to select
one predetermined value, such as yes or no. SET allows the user to select more than
one predetermined value, such as mayonnaise, mustard, tomato, and lettuce to order a
burger. You'll see the following graphic on the bottom of the page when you create a
database table:




The first line in the graphic reminds you to enter values for enum or set as 'mayonnaise',
'mustard', 'tomato', 'lettuce'

Note* You don't have to key each of these tables. In phpMyAdmin, carefully
1. go to my database, kellyc23b.
2. Open my candies table.
3. Click on Operations. On the right, you'll see a copy table form (do not use the Move
table form):




                                                                                           1
4. Select the Structure and data radio button, then key the name of your database in the
blank text field on the right and click Go.
5. Repeat with my cookies and pies tables.
6. Go to your database and you'll see my tables copied there.
7. Check out your Operations menu, you'll see you can do several table operations
there.

candies (candies_id is the primary key)




Which looks like this, (since the graphic above cuts off names)




                                                                                       2
Go through the steps of:
    save as .php
    connect to database
    create recordset
    set up checked values and dynamic links
    insert data

To get:




Next, upload the .php form, check a couple of the boxes, and submit.
Then go into the database and browse, to see if the data are correct:


                                                                        3
Let's try the same process with the other two tables, cookies and pies to see how the
database populates.

With cookies, I want to try to not use y,n, I decide to set up (BTW this is going to fail,
but I want to explain why) values using words such as chocolate chip so that when I
create return pages, the data show, rather than y,n. So, I key the cookie name in the
checked value properties box and again in my dynamic checkbox.




                                                                                             4
The problem, as you can see, is that I did auto-increment with the id number, but the
data did not return with the value I gave it when I set up the form.




The database setup is correct. It's probably best to not have NULL as our option, voids
in databases aren't perfect from a functional perspective. But, for users, I don't want
them to select something like yes chocolate chip, but no peanut butter. It's a little
confusing because here in the record, it would be simple to have a y or an n. Maybe we
can set the database up differently where SET allows multiple choices and each of
these values is in one record. However, I like to separate out if I want to offer later
search options. For example, maybe if users select chocolate chip cookies, I offer
several recipes to make them or ways to serve them. In that case, I am not setting up
for a quick vote, I'm setting up so that I can index each item if I want to add additional
sort and information capabilities.

There could be an issue that I'm setting up ENUM with only one option, chocolate chip,
rather than chocolate chip and nothing. But, let's assume that the issue is how we are
setting things up in Dreamweaver.

This would be easy to follow if we were using text boxes. Visualize that someone keys
in their name address and email. In that case, clearly a 'y', 'n' combination wouldn't
work. The data entered into the record would be a person's name, address, and email.
We would set up something like a table for the output. With checkboxes and radio
buttons, however, we need to signal something is turned on or off and yet we don't want
to return simply that yes it is turned on or no it isn't. In some cases this will work, but in
most, we want it to return information, similar to our expectations for a text box.

Back to cookies, if the form:


                                                                                             5
is set up as:




with the checked value as y:




The database table is populated as:


                                      6
Again, no data is in the table. We set up as y in Dreamweaver, however, that is not how
we have the values identified in the field, so it still doesn't work.

If we leave the checked value as y, but change the dynamic checkbox as equal to:




The database doesn't populate. What can we do?

This type of troubleshooting is common. We slow down and ask what is it we're trying to
accomplish. We want to use ENUM. But we don't want to return a checked value of y or
n. What do we want to return? We want the words chocolate chip to return. What are
words? They are text.

I go back to Dreamweaver and set the checked value to the value I want, chocolate
chip, etc.




                                                                                      7
And the dynamic value is also the value I want, chocolate chip.




And when I Insert Record, I use the dropdown menu to change each item to show that
for each value, submit as Text rather than as Checkbox y,n:




                                                                                     8
And when I check the database table, we see:




which shows the first three attempts, because each of the three forms had auto-
increment set. And the fourth attempt which returns the text we will use on the return
page. So, now we know how to set this up using one table. What if we want to use more
than one table? In this example we have cookies and we haven't tried pies.

Remember, that ID in your checkbox setup must match the field name in your database
table. Label can be whatever you like, since it's the cue for users rather than data.




I like to run a quick test with an individual table to make sure I don't have an error:




                                                                                          9
Next, I'll make a form that has both cookies and pies. I'll do this quickly by going back to
my .html file for each, NOT to my .php file. I want to reuse the checkboxes but .php is
too complex to simply copy and paste it around. I grab the pie checkboxes, copy and
paste them below the cookie checkboxes, and create a new .html form with the two
combined. Then I save that new form as .php.




                                                                                          10
When I then go to create a recordset, however, I select the Advanced button because
Simple works great, but only for one table at a time.




Once in Advanced, we name the recordset, and identify the connection, in the same
way you did in Simple Mode.

Toward the bottom left, open up one of the tables. Highlight the field you want and then
you have a choice of 3 SQL buttons to choose from:


                                                                                       11
SELECT

WHERE

ORDER BY

Read this article, for a good foundational understanding of SQL
http://www.adobe.com/devnet/dreamweaver/articles/sql_primer.html

It is a matching language. You define what you want to do, and match it up to the SQL
statement that will make it happen.

For us, we'll stay with SELECT because what we want to do is select items from a table.

One at a time, I select a field, then click on SELECT. You can see the SQL added to the
SQL window.




                                                                                     12
Next, I close the cookies table and open the pies table. Then go through the same
process. You'll see that each field is listed as coming from cookies, pies tables.

If I wanted to further search, and had the database set up, I could say WHERE the item
has chocolate in it or the item has fruit/raisins in it, and I could order by alpha, price, etc.




                                                                                              13
Since the recordset brings the two tables together, when I go to set up Checked value
and the Dynamic link, both tables are included in the Dynamic Data window




At Insert Record, Remember to check each value and Submit as Text, for both the
cookies table and the pies table.




                                                                                        14
Upload your .php and Connections folder (since you created a new Recordset)




Open up your two database tables to see if they have been populated.


                                                                              15
Then treat yourself to a cookie and a piece of pie.

When I'm working on client products and need to troubleshoot databases. I'll create a
fictional short set like candies, cookies, and pie because it allows me to focus on the
code and not be sweating am I goofing up the client's product. Also, it lets me quickly
create a database and form, with a few items, rather than worry if there is something
else wrong in a complex form that is snagging up what I am trying to do.

Homework.
Please either use one of these tables or create a form that you can use in your final
project. Or, you can expand an existing form you have that's already connected and
checkbox. I'd like to see a form linking from your lesson 10 that includes checkboxes,
and I would like to see a return table that shows a result. It's okay if you use one table
only, rather than joining tables. Next lesson I'll go more into SQL.

You may need to refer to your textbook. 858-860.

Also, keep this simple, it's easy to think of a complex checkbox form and get stuck. In
the end, complex checkbox forms don't work well with Dreamweaver and need hand
coding. For our purpose, you can make typical checkboxes as part of a form and keep
your code pretty clean in Dreamweaver.

Thanks, Kelly




                                                                                             16

				
DOCUMENT INFO
Shared By:
Stats:
views:11
posted:4/23/2009
language:English
pages:16