Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Dreamweaver offers robust support for building dynamic applications with, among others, PHP. While some may complain that the code is outdated, the truth is that it still is completely functional and very easy to work with. In this video, I'm going to show you how you can use Dreamweaver to create a basic recordset, complete with URL-driven dynamic data. Ultimately the goal in this exercise is to create what's referred to as a detail page that outputs the results of one database table record.
Let's start by creating a simple database-driven page in Dreamweaver. One of the best ways to do this is to create a comp page that has the static values in it, which you'll replace with dynamic values. Now I have just such a static page found in the Exercise Files/Chapter 5/05_02, called planet_comp.php. I'll open that now. And as you can see, it's a very basic table, with a series of placeholders. We created a database connection in the first video of this chapter, "Extending the WordPress database." In order to take advantage of that connection, I am going to need to save this file into our local site root.
So I'll choose File >Save As, Site Root, and then just click Save. No need to update the links. Okay, we're ready to start work on our recordset, and we do that by opening up the Bindings panel and then clicking the plus sign and choosing Recordset (Query). Now this is going to be a very basic recordset, so we can just use Dreamweaver's simple Recordset interface. I am going to call it rsPlanet, and you'll note that it defaults to the one connection that we have, conTPA.
Remember, we kept a copy of that in our site root, and that's the file that Dreamweaver is now referencing. The table we're looking at is called "planets," and here are all the other tables that you also have access to. We'll accept all of the columns, because we are going to be using all of that information, but I do want to set the filter. So I am going to define this record set to filter by the id, set to the URL Parameter, also id. And since we are pulling in a single record, there's no need to do any sorting. All right! Let's click OK and save our page, and now we are ready to bind the dynamic data to its proper place in the comp.
So I am just going to double-click on placeholder next to Planet here. Let me close down the Files panel a bit and expand our Bindings panel. And now I can choose planetName and then just click Insert and it will replace the selection. Let's do the same thing with the Distance from the sun placeholder, and that's planetFromSun. Click Insert. The number of Moons is listed in the database table as planetMoons. Click Insert again. And the last one is the Length of the Orbit (in Earth Years) and that is, of course, planetOrbit.
Okay, so all of our placeholders have been replaced with dynamic data, but there's one more piece of the puzzle we need to bring in before the page is ready to display data. If you'll recall, we set up the recordset to filter according to a URL value for the variable id. In Dreamweaver, you can test both URL variables through the HTTP Request Settings dialog, and that's found under the Live View Options button, all the way down at the bottom. So let's open up that dialog box and then click on the plus button to add a new URL request. The name is the variable id.
And now we can give it a value, any of the dynamic values that we have. Let's go ahead and start it at 1, which should return the first planet. I'll click OK and let's go into Live view. Let's save those changes, and there is the first planet, Mercury. It has no moons and it's a very short orbit. All right! You can change those values either through the HTTP Request Settings--let's do that now. And let's go to change it to four, which should give us Mars. There is Mars.
You could also change it directly in the address bar. Let's see what Saturn looks like. Saturn is the sixth planet, and it has more than enough moons to go around. Okay, looks like we've got our dynamic Dreamweaver page ready, and now you're ready to integrate that into a custom template WordPress page.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.