Display Dynamic Database-Driven Content Using PHP and MySQL



hello in this video I'm going to show you how to display dynamic results via dynamic URLs in other words I'm going to show you how to get from a page like this with a bunch of links on it to a page like this with a bunch of information on it right just illustrate what's happening here that's what's happening so we've got this page here and it is linked to a details page I like to call it a details page so it's kind of a finished version so I'm going to show you how I like to think about this so here I am on the unfinished page so in my previous video I showed you how to create these dynamic URLs or the diamond dynamic URLs and that they all link to the same page the only difference is if you look down in the left-hand quarter bottom left-hand corner of the screen you're going to see that the URL is almost the same but I'm just passing an ID and that ID happens to correspond to the primary key of the table where the information is stored to show you what that looks like it looks like this so the underlying information is this table called games and those are the primary keys those are the games that's some information about an image that's the genre that's the console we're going to come back to this in a minute here but do understand that's the data-driven part of our site and so we want to connect this page to that details page so the first thing to understand is that you're going to need to do the design first and so when I do the design I like to do it like this so like let's just go to this whatever Zelda link is so notice I just kind of shell it out so I can write title console genre that's where the picture is going to go there's no getting around the design part of this so that's what I do when I'm creating that details page or that page which is going to be populated dynamically I kind of shell it out which is a big placeholder text and then once I've got the design I'm looking for then we'll start concentrating on the process of getting the information onto that page so let's have a look at the code and start putting it together so here is the code most of it we're not going to look at it obviously there's some CSS and HTML happening require script the underlying query is just diskless this is what you need to care about the rest of this is just housekeeping stuff so this big is set and I'm saying hey if that IDs there too let's do our thing if that ID is not there and you can see the else block is right here then bounce them out of here now I'll show you what I mean by that because this is actually important in the event that this IDs not here I don't know why it wouldn't be there but if it was in there it's going to kick you out and send you back to some other page you'll see that's the redirect you might be wondering what the heck is that page don't worry about it just I'm just pointing out that I did get redirected so either that ID is there which makes everything work or it's not and I kick you right out so this stuff like I said you don't need to worry about there's there's more stuff going on here than it looks like the part that I want you to care about is just this simple query right here so select star from games where image ID equals ID right I don't know if you remember that table I showed you a minute ago but the primary key was image ID so just a simple query and I process the query and I pick out the row right there should only be a single row with that ID if there was more than one row and I don't know what I was doing on primary Keys so that's my data right that variable right there called row is what has everything in it and so the part of the page where as the information is here write the rest of this is just CSS HTML and general logic so instead of just that generic title word what I want to do is I want to bust into a little inline PHP so just be right left bracket question mark PHP I'm going to do this in line and it's quite simply just going to as well I say it's simple it's kind of is I'm just going to do a little echo another thing that I want to echo out is the variable called row and at this point I need to know what that field was called that had the title in it I could just guess that it's called title which I actually don't know or I could go look at my table and go okay title that's the thing I want and so I head over here and just put in title I save and that's the process so really the work is is right in the query and just designing the page once you've got the page designed then it's just quite simply a matter of just refreshing things and you'll notice when I press refresh that title is no longer going to say title it's going to say Zelda and then I'm going to kind of wash rinse and repeat for console and genre I'll do that kind of just one at a time so instead of those xxx I'm just going to go into some inline PHP and I'm going to do a little simple echo and it's called row again and the field that I want to spit out here is probably called console I don't know about the case sensitivity of it we'll see if I make a mistake and then for genre again same kind of process you notice how I shell it out and then I and then I put in the PHP because this peach feels a little bit ugly anytime you're doing this inline stuff so I kind of like to have the placeholder in there it makes it a little bit easier and let's see how that works because I'm not I don't know if I got those fields right I'm just guessing what they're called now the image well images I debated whether I should even do images it's the same kind of deal just know that at some point I'm going to actually tackle the subject of images but for now I'm just going to do a little hand waving at it what I will tell you is that's the name of the image right there so it is stored in a table and the other thing that you need to know is that those images are actually in this folder called uploads so that's what you need to know so let me show you how you do this so I've got this image tag SRC that's the path to the image and so that folder is called uploads and it's a folder some si forward slash and then now I want to do the name of the image so here is where I'm going to break into a little bit of PHP right it looks real weird embedding it after a forward slash inside of backticks but that's okay and I have no idea what that field was actually called I think it was called just image that should be easy enough so it's row square brackets backtick image and that should give me the path to my image so I will save and I will refresh and there's my image like I said I'll tackle images later it's not a whole lot different in principles and displaying any of the other information the page just the differences it was the more of an attribute of a tag as opposed to just something sitting out there so that's the process of taking a dynamic URL like this and creating a page which is capable of processing that ID and populating a page dynamically very common thing to do in web programming one of the more common things that you're going to do with something like PHP so I hope thanks for watching

21 thoughts on “Display Dynamic Database-Driven Content Using PHP and MySQL

  1. so…… mine is working, but on my product page when i click the details button for any product it bring up only one specific product information from the database…I need to see the rest of the product details for other products, any guidance would be greatly appreciated !!??
    please <3

  2. The tex for the title tags at the title bar is not changing pls helps. I mean the title should the dynamic titles of those things from database table direct not hard coded "My favorite things"

  3. Absolute lifesaver! Thank you ever so much! This and your previous video made me understand the whole concept in about 15 mins unlike spending a whole day, still not knowing and a breakdown; thank you once again!

  4. in his php document, where are the "zelda, duck hunt, metroid etc" coming from? i don't see them anywhere.

  5. bro!!what is "connect133.php" in your code??
    i am using same code but i don't know whether to use "connect133.php" or not??

  6. Please provide a download code in your video…! thats all.. it makes help to us to learn what uve learn! thank you 🙂

  7. sir, pls, can u send or give a link to your code because i have tried severally but my redirected page does not show contents from the database

  8. Nice dude..I was waiting for this type of code but couldn't find anything like this on youtube except yours…Nice job and thanks

Leave a Reply

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