Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Dreamweaver CS5 has server behaviors that let you output code conditionally. There are six options for conditional code built into Dreamweaver CS5, and you can learn from the generated code how to write your own conditions. For this demonstration, I'll use the file tours3.php. It's in the root folder of my current web site. In a previous video, I described how to limit the number of records that were being shown in a particular data set, and then how to add hyperlinks that let the user page through the data set.
I'll open the file in a browser, first copying it over to the web site, and then show that I can click through the Next and Previous, but also show you that, for example, when I'm on the First page, I still see links for First and Previous, and these links don't do anything. And if I'm on the Last page, I still see links for Next and Last. Similarly, I would like to hide those in this condition. So, I'll close the browser and return to Dreamweaver.
First, I'll deal with the condition for the First and Previous links. I'll click and drag to select those links. Then I'll go to the Server Behaviors panel, I'll click the Plus button, and I'll go to Show Region. Here are the six available server behaviors for a conditional code. You can show code if the recordset is empty or not empty, if you're on the first page or not the first page, or if you're on the last page or not the last page. I'm going to select Show if Not First Page, and then make sure that I've selected rsPackages - it's the only available choice - and click OK.
So now, those links will only display if I'm not on the first page of data. Now I'll do the same thing for the Next and Last links. I'll click and drag to select those links, I'll go to Server Behaviors, I'll click the Plus button and choose Show Region, and I'll select Show if Not Last Page, and once again, I'll click OK in the dialog box. Here's what the generated code looks like. The hyperlinks have been wrapped in if clauses.
That examines the current page number of the recordset and compares it to the total number of pages. So, now I'll test the code in the browser. I'll go to Firefox, updating the file on the server, and in the initial display, I see links for Next and Last. If I click Next, I see all four hyperlinks, because now I'm on the middle page. And when I click Last, that takes me to the last set of data and hides those links because they're no longer appropriate.
Now, I'll go Previous. I'll see all four links. I'll click Previous again, and now I'll only see the first two links. So, conditional code is something that's very easy to generate in Dreamweaver. The code itself is a little bit on the complex side, but by using Dreamweaver server behaviors, you save yourself an enormous amount of time, and get a very common behavior that users appreciate.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98060 Viewers
80 Video lessons · 141298 Viewers
59 Video lessons · 59661 Viewers
52 Video lessons · 72898 Viewers
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.