Join David Powers for an in-depth discussion in this video Display a repeating value only once, part of PHP Tips, Tricks, and Techniques.
- [Instructor] Hi I'm David Powers,…and welcome to this week's edition…of PHP Tips and Tricks.…Designed to help you become a smarter,…more productive PHP developer.…When displaying the results of a database query,…presentation is all important.…In this example having the Make repeated…in each row like this impedes readability.…The table would be much easier to read…if each Make were displayed just once.…This week's tip shows how to suppress the duplicate values.…
It's a very simple trick,…so let's get to work.…I'm going to switch to my editing program,…and the database result is displayed here…in this foreach loop on lines 25-31.…We're just displaying three values from the database result,…Make, pricef and description.…And it's this make that we need to suppress…if it's going to be repeated.…To prevent a value from being repeated,…all that's necessary is to compare it with the value…from the previous row.…But before the loop begins,…there is no previous value.…
So we need to initialize a variable before the loop,…
Note: The exercise files are free to all members. The code is commented to enhance your learning, but you will need database connectivity for some files to run as intended.
Skill Level Intermediate
PHP: Managing Persistent Sessionswith David Powers2h 41m Intermediate
New this Week:
1. Weekly Episodes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.