26
c159Feb1215.notebook 1 February 12, 2015 Loops need to:

c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

1

February 12, 2015

Loops need to:

Page 2: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

2

February 12, 2015

The condition is asked before making the decision to enter which means it is possible not to enter the loop.

Page 3: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

3

February 12, 2015

Since the condition is atthe bottom of the loop wewill always execute at leastonce.

Note the semi­colonat the end of the condition in thisstructure.

Page 4: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

4

February 12, 2015

Usually there is no semi­colon here, but it is ok.

Page 5: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

5

February 12, 2015

The set, the check and the change are all doneinside the for. Frequently you will se $ct++ toincrement $ct.

Page 6: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

6

February 12, 2015

Example ­ I start out with an html page to gather the data and pass theinformation to the php which processes it.

Page 7: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

7

February 12, 2015

I reveive the data and store it as $wklb and $wkoz.I then convert the weight to ounces and print out the number of ounces.If the ounces are less than 17 then I use the $firstlb charge. If I executethe else I use a loop to help me figure out the price.In the loop I add the $every4oz to add to the cost and I then subtractthe four ounces from the weight.

Page 8: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

8

February 12, 2015

Page 9: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

9

February 12, 2015

The single quote does not resolve the variables.

The double quote does.

Page 10: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

10

February 12, 2015

Now we are going to startto work with MySQL. Firstwe will create tables andquery those tables usingPUTTY as our tool.

Page 11: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

11

February 12, 2015

We will execute Putty. It is free and can be downloaded for your computers.

Page 12: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

12

February 12, 2015

I entered the host and now I am going to use Colours to set thebackground to white and theforeground to black text.

Page 13: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

13

February 12, 2015

Page 14: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

14

February 12, 2015

Page 15: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

15

February 12, 2015

The first login will get you into cisweb.Then we need to specify using MySQLand login for that.

Page 16: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

16

February 12, 2015

I am using my username, you need to use yours.Note I have specified using mysql.

Enter the MySQL passwordyou were sent.

Page 17: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

17

February 12, 2015

I can create databasesbut students do nothave that power.You have been assigneda couple of databaseswhich you can seeby:show databases;

Once you use one of yourdatabase the database changesand you can now createtables.

Page 18: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

18

February 12, 2015

I have now created a table within mydatabase that I called aaatest.I have an int of 4 characters as my id,a name as string/text/character using varchar which means variable length.Note that major could be char(2) sinceit is a fixed character size of 2. The gpais a decimal with 3 characters, 2 of whichare decimals.

Page 19: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

19

February 12, 2015

Gets a description of the database.

Page 20: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

20

February 12, 2015

Now, following the handout,I am inserting a recordinto the testfirst table.

Page 21: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

21

February 12, 2015

Note numeric are not inquotes by varchar or charfields are enclosed inquotes.

Page 22: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

22

February 12, 2015

select *from testfirst;

will show all of therecords and all thefields on each of the record.

Page 23: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

23

February 12, 2015

If you put a record in and you want to delete it then you can use the delete command andidentify the record to delete. In this case,the record with an idno of 1999 will bedeleted.

Page 24: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

24

February 12, 2015

Here I want to change a recordusing the update. I wanted to changethe idno from 33333 to 3333 forthe record where the name is'Robert Brooks'.

Page 25: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

25

February 12, 2015

Could have beenchar(12) since fixedwidth.

Page 26: c159Feb1215.notebook February 12, 2015cisweb.bristolcc.edu/~pgrocer/audio_smartboard15/CIS159/c159Feb1215.pdfdatabase that I called aaatest. I have an int of 4 characters as my id,

c159Feb1215.notebook

26

February 12, 2015

List the fields that I want to see.

Now I only want to see those fields forrecords where the major is CI.