From the course: PHP for Web Designers
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Using modulo division to establish a repeating series - PHP Tutorial
From the course: PHP for Web Designers
Using modulo division to establish a repeating series
The problem with the mixed arrangements page in the Hansel and Petal site, is that looping through the results of the database query has displayed each item in a separate div. We need to adapt the loop so that four items appear in each div. So we'll have four items going across the page, on each row. It doesn't involve a lot of code, but it does need a little explanation. So let's take a look at the existing code. Go to our code editor, and the loop begins on line 57, and it ends on line 67. Inside there, we've got a div, an unordered list, and one list item. We need some way of adding four items to that unordered list, as we had in the original HTML. So let's analyze what needs to be done. This is the basic structure. Each time the loop runs, you get a div and an unordered list with a single item in it. We need the loop to control the opening and closing tags of the div and unordered list, so that four list items are sandwiched between them. So, the first time that the loop runs, the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
Loading data into MySQL5m 37s
-
Connecting to the database7m 47s
-
Querying the database6m 15s
-
Displaying the results of the query3m 50s
-
Using modulo division to establish a repeating series4m 20s
-
Repeating output at specific intervals in a loop4m 56s
-
Linking to a details page2m 40s
-
Embedding a variable in a query securely6m 5s
-
Handling database errors gracefully--and securely8m 40s
-
-
-