Difference between revisions of "PHP-and-MySQL/C3/MySQL-Part-5/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Time !Narration |- |0:0 |Welcome to mySQL part 5. To echo our data to the user and to display the results from this, we'll need to use "while" statement. |- |0:12 |A…')
 
Line 3: Line 3:
 
!Narration
 
!Narration
 
|-
 
|-
|0:0
+
|00:01
 
|Welcome to mySQL part 5. To echo our data to the user and to display the results from this, we'll need to use "while" statement.
 
|Welcome to mySQL part 5. To echo our data to the user and to display the results from this, we'll need to use "while" statement.
 
|-
 
|-
Line 9: Line 9:
 
|As I mentioned, we have created a row variable and this is "=mysql_fetch_assoc".
 
|As I mentioned, we have created a row variable and this is "=mysql_fetch_assoc".
 
|-
 
|-
|0:19
+
|00:21
 
|This is creating an associative array from our "extract" query which is here.
 
|This is creating an associative array from our "extract" query which is here.
 
|-
 
|-
|0:25
+
|00:27
 
|So we are selecting everything in the "people" table and ordering them by "id" in ascending order.
 
|So we are selecting everything in the "people" table and ordering them by "id" in ascending order.
 
|-
 
|-
|0:33
+
|00:33
 
|Inside our WHILE since we wrote row as an array and its an associative array, row[0] will be wrong because these are numeric.
 
|Inside our WHILE since we wrote row as an array and its an associative array, row[0] will be wrong because these are numeric.
 
|-
 
|-
|0:46
+
|00:46
 
|These are numeric id tags and instead of this we'll use our fieldnames, since this is associative.
 
|These are numeric id tags and instead of this we'll use our fieldnames, since this is associative.
 
|-
 
|-
|1:00
+
|00:59
 
|So, instead of 0 1 2 3 4, we'll be using the actual name.
 
|So, instead of 0 1 2 3 4, we'll be using the actual name.
 
|-
 
|-
|1:07
+
|01:05
 
|Lets create variables from this. Let me say id and then firstname equals, we are using the same structure throughout.
 
|Lets create variables from this. Let me say id and then firstname equals, we are using the same structure throughout.
 
|-
 
|-
|1:16
+
|01:15
 
|So its quite easy to copy and paste this.
 
|So its quite easy to copy and paste this.
 
|-
 
|-
|1:19
+
|01:19
 
|Lets indent this.
 
|Lets indent this.
 
|-
 
|-
|1:24
+
|01:24
 
|So we have 5 altogether.
 
|So we have 5 altogether.
 
|-
 
|-
|1:28
+
|01:28
 
|So that's five and then lets just change. This is a lazy act!
 
|So that's five and then lets just change. This is a lazy act!
 
|-
 
|-
|1:33
+
|01:34
 
|But its just a lot quicker to do this way.
 
|But its just a lot quicker to do this way.
 
|-
 
|-
|1:36
+
|01:38
 
|So lastname and we have the date of birth. We also have the gender.
 
|So lastname and we have the date of birth. We also have the gender.
 
|-
 
|-
|1:47
+
|01:47
 
|We have all our data and now how do we use this?
 
|We have all our data and now how do we use this?
 
|-
 
|-
|1:51
+
|01:51
 
|We need to use the "echo" command.
 
|We need to use the "echo" command.
 
|-
 
|-
|1:55
+
|01:55
 
|There might be a loop inside the middle, at the moment. So anything we echo out will be repeated.
 
|There might be a loop inside the middle, at the moment. So anything we echo out will be repeated.
 
|-
 
|-
|1:59
+
|02:02
 
|Every record we have and that's right, too. We'll repeat this code.
 
|Every record we have and that's right, too. We'll repeat this code.
 
|-
 
|-
|2:03
+
|02:07
 
|For example, I say text here. There are currently 4 records.
 
|For example, I say text here. There are currently 4 records.
 
|-
 
|-
|2:12
+
|02:13
 
|After refreshing this page, you should see text echoed out 4 times.
 
|After refreshing this page, you should see text echoed out 4 times.
 
|-
 
|-
|2:17
+
|02:18
 
|By typing out 4 times, this piece of code here represents every loop.
 
|By typing out 4 times, this piece of code here represents every loop.
 
|-
 
|-
|2:23
+
|02:24
 
|Therefore we can incorporate for example, id or firstname or any other, that we have extracted from the database using our associative array.
 
|Therefore we can incorporate for example, id or firstname or any other, that we have extracted from the database using our associative array.
 
|-
 
|-
|2:33
+
|02:36
 
|Now I'll write firstname lastname was born on dob for date of birth and is and I'll put gender up there.
 
|Now I'll write firstname lastname was born on dob for date of birth and is and I'll put gender up there.
 
|-
 
|-
|2:49
+
|0 2:49
 
|Not forgetting our linebreak. I'll refresh our page.  
 
|Not forgetting our linebreak. I'll refresh our page.  
 
|-
 
|-
|2:55
+
|02:54
 
|Then we have our set of data structured using the variable names.  
 
|Then we have our set of data structured using the variable names.  
 
|-
 
|-
|3:02
+
|02:59
 
|We have given in the correct order and also it has been repeated through for every record we have.
 
|We have given in the correct order and also it has been repeated through for every record we have.
 
|-
 
|-
|3:06
+
|03:08
 
|Okay, we have just given out the content of our table using this star, declared by this asterisk, where it collects every single data or every record.
 
|Okay, we have just given out the content of our table using this star, declared by this asterisk, where it collects every single data or every record.
 
|-
 
|-
|3:20
+
|03:22
 
|Now let me do this. I'll say IF gender==F then gender=female.
 
|Now let me do this. I'll say IF gender==F then gender=female.
 
|-
 
|-
|3:36
+
|03:39
 
|The actual spelling of that and then let us say else gender=male. This is just rewriting the variable depending on the value.
 
|The actual spelling of that and then let us say else gender=male. This is just rewriting the variable depending on the value.
 
|-
 
|-
|3:50
+
|03:50
|If we refresh now, we can see this has changed to male male and female female. We also have some interesting ways of displaying this data.
+
|If we refresh now, we can see this has changed to '''male male''' and '''female female'''. We also have some interesting ways of displaying this data.
 
|-
 
|-
|3:59
+
|04:00
 
|At the moment I'm selecting from the people table and ordering by id and ascending order.
 
|At the moment I'm selecting from the people table and ordering by id and ascending order.
 
|-
 
|-
|4:06
+
|04:07
 
|I can also order by descending id. You can see that this switches this data around.  
 
|I can also order by descending id. You can see that this switches this data around.  
 
|-
 
|-
|4:16
+
|04:15
 
|We can also order it by firstname. This will put this in descending alphabetical order and ascending will put this in ascending alphabetical order.
 
|We can also order it by firstname. This will put this in descending alphabetical order and ascending will put this in ascending alphabetical order.
 
|-
 
|-
|4:32
+
|04:33
|So we got A D E and K.
+
|So we got ''' A D E and K'''.
 
|-
 
|-
|4:34
+
|04:36
 
|You can do the same with the surname.
 
|You can do the same with the surname.
 
|-
 
|-
|4:36
+
|04:39
 
|You could do the same with anything. Even Date of birth, as long as you include this over here.  
 
|You could do the same with anything. Even Date of birth, as long as you include this over here.  
 
|-
 
|-
|4:44
+
|04:46
 
|Another thing to do is, let me just take this back to id and have this as descending. We can use this limit 1 or we can say limit 2, 3 or 4.
 
|Another thing to do is, let me just take this back to id and have this as descending. We can use this limit 1 or we can say limit 2, 3 or 4.
 
|-
 
|-
|4:57
+
|04:58
 
|Now I'll limit 1 for the purpose of this.
 
|Now I'll limit 1 for the purpose of this.
 
|-
 
|-
|4:59
+
|05:00
 
|Now lets have 1 to let the user of the page know the last person that was inserted into this table.
 
|Now lets have 1 to let the user of the page know the last person that was inserted into this table.
 
|-
 
|-
|5:10
+
|05:11
 
|So I say "echo" here.
 
|So I say "echo" here.
 
|-
 
|-
|5:13
+
|05:16
 
|echo last person to be inserted into table was and I'll leave it like that and add a linebreak.  
 
|echo last person to be inserted into table was and I'll leave it like that and add a linebreak.  
 
|-
 
|-
|5:28
+
|05:27
 
|I'll just echo out the first and last name. Ok?
 
|I'll just echo out the first and last name. Ok?
 
|-
 
|-
|5:33
+
|05:33
 
|So, here we can see that there is a lot of confusion.
 
|So, here we can see that there is a lot of confusion.
 
|-
 
|-
|5:37
+
|05:38
 
|Last person to be inserted. Yes, in fact it does work!
 
|Last person to be inserted. Yes, in fact it does work!
 
|-
 
|-
|5:40
+
|05:43
 
|It is already typed in the "limit" command.
 
|It is already typed in the "limit" command.
 
|-
 
|-
|5:42
+
|05:46
 
|What I've done is by limiting this by 1 in descending order of id - the id is incremental - I get 4 at the top and if we are limiting it by 1, 4 will be the only record that is selected.  
 
|What I've done is by limiting this by 1 in descending order of id - the id is incremental - I get 4 at the top and if we are limiting it by 1, 4 will be the only record that is selected.  
 
|-
 
|-
|6:02
+
|06:01
 
|Therefore, the last person in the table, as per the last record displayed, will have its value echoed out.  
 
|Therefore, the last person in the table, as per the last record displayed, will have its value echoed out.  
 
|-
 
|-
|6:09
+
|06:09
 
|This "while" will only return 1 data value.
 
|This "while" will only return 1 data value.
 
|-
 
|-
|6:12
+
|06:13
 
|Since we are returning 1 data value here, we are confused by these.
 
|Since we are returning 1 data value here, we are confused by these.
 
|-
 
|-
|6:17
+
|06:18
|This is one command here, "select * from people", "order by id decs" is another and "limit 1" is yet another.  
+
|This is one command here, so lets" * from people", "order by id decs" is another and "limit 1" is yet another.  
 
|-
 
|-
|6:26
+
|06:27
 
|We don't use commas or anything. This is just how we write our code inside our query.
 
|We don't use commas or anything. This is just how we write our code inside our query.
 
|-
 
|-
|6:36
+
|06:34
|Okay, just to test this code, I'll insert just using the "insert" function in php myadmin and I'll insert another record.
+
|Okay, just to test this , I'll insert just using the "insert" function in php myadmin and I'll insert another record.
 
|-
 
|-
|6:44
+
|06:45
 
|For example, lets type in "David Green" and our date of birth could be random.
 
|For example, lets type in "David Green" and our date of birth could be random.
 
|-
 
|-
|6:53
+
|06:55
 
|It doesn't really matter what we type in here. We say male.  
 
|It doesn't really matter what we type in here. We say male.  
 
|-
 
|-
|7:00
+
|07:00
|I come down here and submit this data.
+
|I came down here and submit this data.
 
|-
 
|-
|7:02
+
|07:02
 
|Click on browse and we have a new value here.  
 
|Click on browse and we have a new value here.  
 
|-
 
|-
|7:03
+
|07:06
 
|When we come back here and refresh, that will change to "David Green".
 
|When we come back here and refresh, that will change to "David Green".
 
|-
 
|-
|7:11
+
|07:10
 
|So this is really useful if you have a website in which your putting videos or personal pictures.  
 
|So this is really useful if you have a website in which your putting videos or personal pictures.  
 
|-
 
|-
|7:18
+
|07:17
 
|You can just place in the last thing the user had inserted.  
 
|You can just place in the last thing the user had inserted.  
 
|-
 
|-
|7:21
+
|07:21
 
|Or may be the last person that has been registered on your website or anything.  
 
|Or may be the last person that has been registered on your website or anything.  
 
|-
 
|-
|7:26
+
|07:30
 
|Possibility of using this is endless.
 
|Possibility of using this is endless.
 
|-
 
|-
|7:28
+
|07:33
 
|Basically how to echo out data and how to manipulate it by just using mysql query.
 
|Basically how to echo out data and how to manipulate it by just using mysql query.
 
|-
 
|-
|7:35
+
|07:44
 
|In the next part, we will allow our user to specify which data they want to show.
 
|In the next part, we will allow our user to specify which data they want to show.
 
|-
 
|-
|7:45
+
|07:50
 
|We will create some html forms and to enable them to do this.
 
|We will create some html forms and to enable them to do this.
 
|-
 
|-
|7:50
+
|07:55
 
|This will let them select a name from the database or table of their choice.
 
|This will let them select a name from the database or table of their choice.
 
|-
 
|-
|7:55
+
|08:00
 
|So, join me in the next part.
 
|So, join me in the next part.
 
|-
 
|-
|8:03
+
|08:01
 
|Bye for now.  This is Juanita Jayakar dubbing for the Spoken Tutorial Project
 
|Bye for now.  This is Juanita Jayakar dubbing for the Spoken Tutorial Project

Revision as of 16:27, 12 July 2013

Time Narration
00:01 Welcome to mySQL part 5. To echo our data to the user and to display the results from this, we'll need to use "while" statement.
0:12 As I mentioned, we have created a row variable and this is "=mysql_fetch_assoc".
00:21 This is creating an associative array from our "extract" query which is here.
00:27 So we are selecting everything in the "people" table and ordering them by "id" in ascending order.
00:33 Inside our WHILE since we wrote row as an array and its an associative array, row[0] will be wrong because these are numeric.
00:46 These are numeric id tags and instead of this we'll use our fieldnames, since this is associative.
00:59 So, instead of 0 1 2 3 4, we'll be using the actual name.
01:05 Lets create variables from this. Let me say id and then firstname equals, we are using the same structure throughout.
01:15 So its quite easy to copy and paste this.
01:19 Lets indent this.
01:24 So we have 5 altogether.
01:28 So that's five and then lets just change. This is a lazy act!
01:34 But its just a lot quicker to do this way.
01:38 So lastname and we have the date of birth. We also have the gender.
01:47 We have all our data and now how do we use this?
01:51 We need to use the "echo" command.
01:55 There might be a loop inside the middle, at the moment. So anything we echo out will be repeated.
02:02 Every record we have and that's right, too. We'll repeat this code.
02:07 For example, I say text here. There are currently 4 records.
02:13 After refreshing this page, you should see text echoed out 4 times.
02:18 By typing out 4 times, this piece of code here represents every loop.
02:24 Therefore we can incorporate for example, id or firstname or any other, that we have extracted from the database using our associative array.
02:36 Now I'll write firstname lastname was born on dob for date of birth and is and I'll put gender up there.
0 2:49 Not forgetting our linebreak. I'll refresh our page.
02:54 Then we have our set of data structured using the variable names.
02:59 We have given in the correct order and also it has been repeated through for every record we have.
03:08 Okay, we have just given out the content of our table using this star, declared by this asterisk, where it collects every single data or every record.
03:22 Now let me do this. I'll say IF gender==F then gender=female.
03:39 The actual spelling of that and then let us say else gender=male. This is just rewriting the variable depending on the value.
03:50 If we refresh now, we can see this has changed to male male and female female. We also have some interesting ways of displaying this data.
04:00 At the moment I'm selecting from the people table and ordering by id and ascending order.
04:07 I can also order by descending id. You can see that this switches this data around.
04:15 We can also order it by firstname. This will put this in descending alphabetical order and ascending will put this in ascending alphabetical order.
04:33 So we got A D E and K.
04:36 You can do the same with the surname.
04:39 You could do the same with anything. Even Date of birth, as long as you include this over here.
04:46 Another thing to do is, let me just take this back to id and have this as descending. We can use this limit 1 or we can say limit 2, 3 or 4.
04:58 Now I'll limit 1 for the purpose of this.
05:00 Now lets have 1 to let the user of the page know the last person that was inserted into this table.
05:11 So I say "echo" here.
05:16 echo last person to be inserted into table was and I'll leave it like that and add a linebreak.
05:27 I'll just echo out the first and last name. Ok?
05:33 So, here we can see that there is a lot of confusion.
05:38 Last person to be inserted. Yes, in fact it does work!
05:43 It is already typed in the "limit" command.
05:46 What I've done is by limiting this by 1 in descending order of id - the id is incremental - I get 4 at the top and if we are limiting it by 1, 4 will be the only record that is selected.
06:01 Therefore, the last person in the table, as per the last record displayed, will have its value echoed out.
06:09 This "while" will only return 1 data value.
06:13 Since we are returning 1 data value here, we are confused by these.
06:18 This is one command here, so lets" * from people", "order by id decs" is another and "limit 1" is yet another.
06:27 We don't use commas or anything. This is just how we write our code inside our query.
06:34 Okay, just to test this , I'll insert just using the "insert" function in php myadmin and I'll insert another record.
06:45 For example, lets type in "David Green" and our date of birth could be random.
06:55 It doesn't really matter what we type in here. We say male.
07:00 I came down here and submit this data.
07:02 Click on browse and we have a new value here.
07:06 When we come back here and refresh, that will change to "David Green".
07:10 So this is really useful if you have a website in which your putting videos or personal pictures.
07:17 You can just place in the last thing the user had inserted.
07:21 Or may be the last person that has been registered on your website or anything.
07:30 Possibility of using this is endless.
07:33 Basically how to echo out data and how to manipulate it by just using mysql query.
07:44 In the next part, we will allow our user to specify which data they want to show.
07:50 We will create some html forms and to enable them to do this.
07:55 This will let them select a name from the database or table of their choice.
08:00 So, join me in the next part.
08:01 Bye for now. This is Juanita Jayakar dubbing for the Spoken Tutorial Project

Contributors and Content Editors

Minal, PoojaMoolya, Pratik kamble, Sandhya.np14, Sneha