PHP MySQL in DreamHost Tutorial 6 – Display database data in HTML Video Tutorial DreamHost

Sign up DreamHost
PHP MySQL in DreamHost Tutorial 6 – Display database data in HTML

 Video Tutorial DreamHost

PHP MySQL in DreamHost Tutorial 6 – Display database data in HTML

Tutorial Hosting
Welcome back everybody to you’re setting up PHP and MySQL and dreamhost tutorial series I’m Caleb from cable videomaker – and I just I just think we should just dive right in so from the last video we officially connected to the database without any errors but we still have

Nothing on the page to show for it what’s the point in doing all that work if you have nothing to show for it so what we want to do is we want to take the database content and display it on the page and that can be useful for so

Many things a lot of web pages are used for what’s known as crud create read update and delete so essentially we are doing one of those four things in this video series we are going to read that data from the database and if you don’t really understand all of that that’s

Okay you don’t need to have a full understanding to follow this little video essentially we’re just taking the database and echoing it on the screen very simple so let’s go to our code and the very first thing we need to do is put a semicolon to end that statement

That will allow us to add more to our script now we need to reference this connection but how do we go about doing that because up here we are just connecting and then putting a semicolon and that’s it well the way we do this is we assign this whole thing to a variable

And you declare variables in PHP with a dollar sign and then the name so we’re just going to call this – oops MySQL I and we are going to set that equal to or assign this this value so basically whatever this evaluates to we are assigning it to this variable so

Essentially whenever we need to talk to the database we can reference this variable so now we can execute a query on our database by referencing this variable MySQL I then we need to access a function inside of this variable and if you don’t know functions and all that

Good stuff it doesn’t really matter essentially we need to make this little arrow thing and we need to say query and this is a function that’s going to take some more pram the parameters that at once is the query itself so as if we were writing in PHP myadmin

SQL window you just put the same query that you want to put right here so in the previous videos I did select everything from tutorials I’m going to use that same command here when you try writing this out you might do something like this but you will find that this is

Going to cause you errors because the query itself actually has to be in quotes so what I’m going to do is I’m going to surround this with double quotes then end up with a semicolon and then what we need to do is we need to take the result of this whole thing and

Assign it to a new variable so if we go up a line we can create a variable call it result and set it equal to this whole statement so now the result of this query is going to be stored in this variable called result now to display

Stuff on the screen we use the echo command but if you try this you’ll find that it’s not going to work the way we want I’ll show you here let’s save it and then I will go to FileZilla upload refresh oh man could not be converted to

String so rather than going through a process to convert this to a string we’re just going to do something even cooler so let’s let’s just get rid of this line for now we’re going to use what’s known as a for each loop within here we are going to give the loop

Something we can iterate over that means we can go through one step at a time so we can actually pass the result into this for each loop and then we say as and then we name every single item in that result set so if you know if you guys don’t have programming experience

This might be a little bit much but just follow along it’ll make sense as we go along so we want to reference every single item in this result set well this result set is going to return I think four rows so the thing is we want a name or

The Rose so we can name it ro so essentially we are going to iterate through this table and we can reference the row using this name so let’s try it now let’s echo out this row and see what happens save yes refresh okay you can see we get the

Result arrey arrey arrey arrey you’re probably wondering why well the reason is because we’re taking the rose and trying to echo them all out at once so PHP sees that as an array and it just echoes array so what we need to do is we actually need to iterate over every

Single column inside of that array so we need to nest another for each loop inside of this for each loop so now what are we iterating over we’re iterating over each row and what is it we want to access within the row we want to access

The column or if you want to name it a little more specifically you could say the field because that is an individual value for a column and then within here we could echo the field let’s save it yes refresh okay we got something we got array one joining dreamhost

Array two creating our database array three filezilla array for PHP myadmin so obviously this is not exactly what we were looking for so we need to fix this up a little bit the first thing I don’t think we need this echo statement here because all it

Does is say array it’s it’s useless so I’m gonna get rid of that at least now all we’ll have is the ID and then the name of the article so we’re getting closer so the next thing I’m going to do is I’m going to put a space after the

Field so the way you do that is with a dot and then inside of quotes put a space now let’s upload it and see what it looks like great we’re getting closer the next thing I want to do is on every single line I only want one row so I want this

To be on a separate line so how do we do that let’s go back and it’s actually pretty easy after every single row we want to make a new line so all we got to do is say echo and we can actually put HTML inside of here so we could say break

Crate that looks so much better so that is essentially what we were going for but there is still a couple of things that you could do to improve this next what we can do is put everything inside of a paragraph we want to do that with

Each row because we want each row to be a paragraph not each field so what we do is here echo quotes we’re gonna open a paragraph tag in that statement and then down here we’re going to echo the closing tag we’re no longer going to need this break statement because

Paragraphs by default break down to the next line so it’s kind of unneeded it would just give extra space so I saved it let’s see what it does great it’s actually looking pretty darn good that has the basics of displaying data in a webpage and you can see if you

Actually either inspect this and view the source or just inspect it you can see how this actually does create HTML we have HTML head head body paragraphs head body so that is it guys hopefully that was a lot of help if you guys have any questions at all leave a comment and

Keep watching this playlist because if there’s anything simple I can do I will make another video I’m probably gonna cancel this hosting so I try to do it within the next month once once that’s over I’m not gonna have access to this website any longer so if you guys have

Any suggestions or anything just leave a comment and thank you guys please be sure to subscribe and I will see you guys in the next video you
Start your career as a software developer – https://calcur.tech/dev-fundamentals 💯 FREE courses (100+ hours) – https://calcur.tech/all-in-ones 🐍 Python course – https://calcur .tech /python-courses ✅ Data Structures and Algorithms – https://calcur.tech/dsa-youtube ~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~ ~ ~~ ✉️ Newsletter – https://calcur.tech/newsletter 📸 Instagram – https://www.instagram.com/CalebCurry 🐦 Twitter – https://twitter.com/calebCurry 🔗 LinkedIn – https://www. linkedin .com/in/calebcurry ▶️ Subscribe – http://calcur.tech/subscribe 👨🏻‍🎓 Courses – https://www.codebreakthrough.com ~~~~~~~~~~~~~~ SUPPORT ME ~ ~~~~~~~~~~~~~ ↪ My Amazon Store – https://www.amazon.com/shop/calebcurry 🅿 Patreon – http://calcur.tech/patreon-calebcurry 🅖 GitHub Sponsors – https ://github.com/sponsors/CalebCurry Ⓟ Paypal – http://paypal.me/calcur 🅑 Bitcoin – 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq 🅔 Eth – 0x350139af84b60d075a3a0379716040b63f6D3853 📈 Buy Bitcoin – https://calcur.tech/crypto Reserve the Ruby Steel -Crypto Rewards Card and get a $25 bonus (use affiliate code “Caleb”) – https://calcur.tech/crypto
#PHP #MySQL #DreamHost #Tutorial #Display #database #data #HTML


https://i.ytimg.com/vi/pcyvH-lEznY/hqdefault.jpg

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

Lost Password