<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC3%2FMySQL-Part-5%2FEnglish</id>
		<title>PHP-and-MySQL/C3/MySQL-Part-5/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC3%2FMySQL-Part-5%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C3/MySQL-Part-5/English&amp;action=history"/>
		<updated>2026-04-06T01:16:41Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C3/MySQL-Part-5/English&amp;diff=557&amp;oldid=prev</id>
		<title>Chandrika: 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 &quot;while&quot; statement. |- |0:12 |A…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C3/MySQL-Part-5/English&amp;diff=557&amp;oldid=prev"/>
				<updated>2012-11-29T06:47:56Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| 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&amp;#039;ll need to use &amp;quot;while&amp;quot; statement. |- |0:12 |A…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Time&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
|0:0&lt;br /&gt;
|Welcome to mySQL part 5. To echo our data to the user and to display the results from this, we'll need to use &amp;quot;while&amp;quot; statement.&lt;br /&gt;
|-&lt;br /&gt;
|0:12&lt;br /&gt;
|As I mentioned, we have created a row variable and this is &amp;quot;=mysql_fetch_assoc&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|0:19&lt;br /&gt;
|This is creating an associative array from our &amp;quot;extract&amp;quot; query which is here.&lt;br /&gt;
|-&lt;br /&gt;
|0:25&lt;br /&gt;
|So we are selecting everything in the &amp;quot;people&amp;quot; table and ordering them by &amp;quot;id&amp;quot; in ascending order.&lt;br /&gt;
|-&lt;br /&gt;
|0:33&lt;br /&gt;
|Inside our WHILE since we wrote row as an array and its an associative array, row[0] will be wrong because these are numeric.&lt;br /&gt;
|-&lt;br /&gt;
|0:46&lt;br /&gt;
|These are numeric id tags and instead of this we'll use our fieldnames, since this is associative.&lt;br /&gt;
|-&lt;br /&gt;
|1:00&lt;br /&gt;
|So, instead of 0 1 2 3 4, we'll be using the actual name.&lt;br /&gt;
|-&lt;br /&gt;
|1:07&lt;br /&gt;
|Lets create variables from this. Let me say id and then firstname equals, we are using the same structure throughout.&lt;br /&gt;
|-&lt;br /&gt;
|1:16&lt;br /&gt;
|So its quite easy to copy and paste this.&lt;br /&gt;
|-&lt;br /&gt;
|1:19&lt;br /&gt;
|Lets indent this.&lt;br /&gt;
|-&lt;br /&gt;
|1:24&lt;br /&gt;
|So we have 5 altogether.&lt;br /&gt;
|-&lt;br /&gt;
|1:28&lt;br /&gt;
|So that's five and then lets just change. This is a lazy act!&lt;br /&gt;
|-&lt;br /&gt;
|1:33&lt;br /&gt;
|But its just a lot quicker to do this way.&lt;br /&gt;
|-&lt;br /&gt;
|1:36&lt;br /&gt;
|So lastname and we have the date of birth. We also have the gender.&lt;br /&gt;
|-&lt;br /&gt;
|1:47&lt;br /&gt;
|We have all our data and now how do we use this?&lt;br /&gt;
|-&lt;br /&gt;
|1:51&lt;br /&gt;
|We need to use the &amp;quot;echo&amp;quot; command.&lt;br /&gt;
|-&lt;br /&gt;
|1:55&lt;br /&gt;
|There might be a loop inside the middle, at the moment. So anything we echo out will be repeated.&lt;br /&gt;
|-&lt;br /&gt;
|1:59&lt;br /&gt;
|Every record we have and that's right, too. We'll repeat this code.&lt;br /&gt;
|-&lt;br /&gt;
|2:03&lt;br /&gt;
|For example, I say text here. There are currently 4 records.&lt;br /&gt;
|-&lt;br /&gt;
|2:12&lt;br /&gt;
|After refreshing this page, you should see text echoed out 4 times.&lt;br /&gt;
|-&lt;br /&gt;
|2:17&lt;br /&gt;
|By typing out 4 times, this piece of code here represents every loop.&lt;br /&gt;
|-&lt;br /&gt;
|2:23&lt;br /&gt;
|Therefore we can incorporate for example, id or firstname or any other, that we have extracted from the database using our associative array.&lt;br /&gt;
|-&lt;br /&gt;
|2:33&lt;br /&gt;
|Now I'll write firstname lastname was born on dob for date of birth and is and I'll put gender up there.&lt;br /&gt;
|-&lt;br /&gt;
|2:49&lt;br /&gt;
|Not forgetting our linebreak. I'll refresh our page. &lt;br /&gt;
|-&lt;br /&gt;
|2:55&lt;br /&gt;
|Then we have our set of data structured using the variable names. &lt;br /&gt;
|-&lt;br /&gt;
|3:02&lt;br /&gt;
|We have given in the correct order and also it has been repeated through for every record we have.&lt;br /&gt;
|-&lt;br /&gt;
|3:06&lt;br /&gt;
|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.&lt;br /&gt;
|-&lt;br /&gt;
|3:20&lt;br /&gt;
|Now let me do this. I'll say IF gender==F then gender=female.&lt;br /&gt;
|-&lt;br /&gt;
|3:36&lt;br /&gt;
|The actual spelling of that and then let us say else gender=male. This is just rewriting the variable depending on the value.&lt;br /&gt;
|-&lt;br /&gt;
|3:50&lt;br /&gt;
|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.&lt;br /&gt;
|-&lt;br /&gt;
|3:59&lt;br /&gt;
|At the moment I'm selecting from the people table and ordering by id and ascending order.&lt;br /&gt;
|-&lt;br /&gt;
|4:06&lt;br /&gt;
|I can also order by descending id. You can see that this switches this data around. &lt;br /&gt;
|-&lt;br /&gt;
|4:16&lt;br /&gt;
|We can also order it by firstname. This will put this in descending alphabetical order and ascending will put this in ascending alphabetical order.&lt;br /&gt;
|-&lt;br /&gt;
|4:32&lt;br /&gt;
|So we got A D E and K.&lt;br /&gt;
|-&lt;br /&gt;
|4:34&lt;br /&gt;
|You can do the same with the surname.&lt;br /&gt;
|-&lt;br /&gt;
|4:36&lt;br /&gt;
|You could do the same with anything. Even Date of birth, as long as you include this over here. &lt;br /&gt;
|-&lt;br /&gt;
|4:44&lt;br /&gt;
|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.&lt;br /&gt;
|-&lt;br /&gt;
|4:57&lt;br /&gt;
|Now I'll limit 1 for the purpose of this.&lt;br /&gt;
|-&lt;br /&gt;
|4:59&lt;br /&gt;
|Now lets have 1 to let the user of the page know the last person that was inserted into this table.&lt;br /&gt;
|-&lt;br /&gt;
|5:10&lt;br /&gt;
|So I say &amp;quot;echo&amp;quot; here.&lt;br /&gt;
|-&lt;br /&gt;
|5:13&lt;br /&gt;
|echo last person to be inserted into table was and I'll leave it like that and add a linebreak. &lt;br /&gt;
|-&lt;br /&gt;
|5:28&lt;br /&gt;
|I'll just echo out the first and last name. Ok?&lt;br /&gt;
|-&lt;br /&gt;
|5:33&lt;br /&gt;
|So, here we can see that there is a lot of confusion.&lt;br /&gt;
|-&lt;br /&gt;
|5:37&lt;br /&gt;
|Last person to be inserted. Yes, in fact it does work!&lt;br /&gt;
|-&lt;br /&gt;
|5:40&lt;br /&gt;
|It is already typed in the &amp;quot;limit&amp;quot; command.&lt;br /&gt;
|-&lt;br /&gt;
|5:42&lt;br /&gt;
|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. &lt;br /&gt;
|-&lt;br /&gt;
|6:02&lt;br /&gt;
|Therefore, the last person in the table, as per the last record displayed, will have its value echoed out. &lt;br /&gt;
|-&lt;br /&gt;
|6:09&lt;br /&gt;
|This &amp;quot;while&amp;quot; will only return 1 data value.&lt;br /&gt;
|-&lt;br /&gt;
|6:12&lt;br /&gt;
|Since we are returning 1 data value here, we are confused by these.&lt;br /&gt;
|-&lt;br /&gt;
|6:17&lt;br /&gt;
|This is one command here, &amp;quot;select * from people&amp;quot;, &amp;quot;order by id decs&amp;quot; is another and &amp;quot;limit 1&amp;quot; is yet another. &lt;br /&gt;
|-&lt;br /&gt;
|6:26&lt;br /&gt;
|We don't use commas or anything. This is just how we write our code inside our query.&lt;br /&gt;
|-&lt;br /&gt;
|6:36&lt;br /&gt;
|Okay, just to test this code, I'll insert just using the &amp;quot;insert&amp;quot; function in php myadmin and I'll insert another record.&lt;br /&gt;
|-&lt;br /&gt;
|6:44&lt;br /&gt;
|For example, lets type in &amp;quot;David Green&amp;quot; and our date of birth could be random.&lt;br /&gt;
|-&lt;br /&gt;
|6:53&lt;br /&gt;
|It doesn't really matter what we type in here. We say male. &lt;br /&gt;
|-&lt;br /&gt;
|7:00&lt;br /&gt;
|I come down here and submit this data.&lt;br /&gt;
|-&lt;br /&gt;
|7:02&lt;br /&gt;
|Click on browse and we have a new value here. &lt;br /&gt;
|-&lt;br /&gt;
|7:03&lt;br /&gt;
|When we come back here and refresh, that will change to &amp;quot;David Green&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|7:11&lt;br /&gt;
|So this is really useful if you have a website in which your putting videos or personal pictures. &lt;br /&gt;
|-&lt;br /&gt;
|7:18&lt;br /&gt;
|You can just place in the last thing the user had inserted. &lt;br /&gt;
|-&lt;br /&gt;
|7:21&lt;br /&gt;
|Or may be the last person that has been registered on your website or anything. &lt;br /&gt;
|-&lt;br /&gt;
|7:26&lt;br /&gt;
|Possibility of using this is endless.&lt;br /&gt;
|-&lt;br /&gt;
|7:28&lt;br /&gt;
|Basically how to echo out data and how to manipulate it by just using mysql query.&lt;br /&gt;
|-&lt;br /&gt;
|7:35&lt;br /&gt;
|In the next part, we will allow our user to specify which data they want to show.&lt;br /&gt;
|-&lt;br /&gt;
|7:45&lt;br /&gt;
|We will create some html forms and to enable them to do this.&lt;br /&gt;
|-&lt;br /&gt;
|7:50&lt;br /&gt;
|This will let them select a name from the database or table of their choice.&lt;br /&gt;
|-&lt;br /&gt;
|7:55&lt;br /&gt;
|So, join me in the next part.&lt;br /&gt;
|-&lt;br /&gt;
|8:03&lt;br /&gt;
|Bye for now.  This is Juanita Jayakar dubbing for the Spoken Tutorial Project&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>