Entries tagged "PHP"

Sorting HTML Data Tables Part 2: Dynamically Sort in Ascending and Descending Order

In last week's post we looked at dynamically sorting HTML data tables. But we only talked about sorting the columns in either ascending or descending. If the user is looking for a last name that appears near the end of the alphabet and the column is sorted from A to Z, they may have a lot of names to go through before finding the one they want. Instead we could provide an option for sorting in both descending and ascending order. [Continue reading]

Sorting HTML Data Tables Using the Header Row with PHP

When displaying a data tables, how do you usually sort the information? Do you sort by the field that you think is the most important to the visitor? For example, it's perfectly acceptable to show a list of order by date; showing the newest order first. But what if the user wants the data organized differently? We could let them choose the column to sort by. [Continue reading]

Maintaining a Hidden Content Archive Within a PHP Page

Do you have content that cycles regularly, such as a news feed, events calendar, etc. If so, there's a good chance that the current entries would serve as useful templates for future updates. "But where do I store these content templates?" Hey, thanks for asking. If you normally delete old information and are unsure where/how to archive it, let's take a closer look at one of the methods described in last week's post (Three Simple Methods for Hiding Website Content Until It’s Ready)—hiding content with PHP comments. [Continue reading]

Three Simple Methods for Hiding Website Content Until It’s Ready

How do you handle content that needs to be temporarily removed from a website? Maybe there is some text that gets recycled on a regular basis or something that hasn't been approved for posting yet. HTML comments could be utilized to hide everything until it's ready to go live. Just keep in mind that the content is still accessible via the browser for those who know where to look. If that's an issue, the information could be moved to a separate file and saved offline…or you could use PHP comments. [Continue reading]

Utilizing the Short-hand if() within a PHP String

Until recently, one thing has eluded me when it comes to the Ternary Operator [aka the short-hand if()]. It's easy to assign the resulting value to a variable or to display it on the screen, but how is the short-hand if() used in conjunction with the concatenation character? In other words, how is it used in the middle of a PHP string? [Continue reading]

Getting Your Projects Done Faster by Writing Less Code with the Short-hand if()

Have you coded a simple if() construct that sets a variable to one of two values and thought to yourself "Five lines of code; there should be a better way?" Okay, maybe it's just me. Either way, let's take a look at the Ternary Operator [aka the short-hand if()]. [Continue reading]

Condensing if() Constructs to Improve the Scanability of Your Code

In a previous post, we went through the typical setup for the if() construct. The good thing (or bad) is that there's a lot of freedom when it comes to writing code. You could for example write the entire if() construct that contains dozens of lines of code and never use a line break. You could, but I wouldn't necessarily recommend it. However, there are other non-"standard" ways of writing out your if() constructs. [Continue reading]

Small Changes to Make If Statements Easier to Scan

When developing programs with hundreds of lines of code, it's beneficial to write code that's easy to scan. That way when you need to update the program months or years later, it will be much easier to follow along. In addition to breaking the code into logical chunks, adding comments, etc. it's helpful to indent code which only gets executed given a specific criteria. For example, all the code within the if/else statement. [Continue reading]

Changing Database Entries on the Fly by Embedding PHP Variables

When pulling information from a database, have you ever needed to change aspects of the text on the fly. For example, let's say you have a form which is populated from a database with questions like "Did you utilize any of the website resources in 2011?" If the form is submitted annually, the 2011 needs to correspond with the year the form is being filled out by visitors. You could remove the year, but what if the question becomes too vague without it. In a perfect world, we could store a PHP variable in the database along with the question, but we can't do that…can we? [Continue reading]

Reduce Website Maintenance by Importing Common Contact Information with PHP

While working on websites, one thing I've learned over the years is that change happens. People will leave the organization. Organizations change names. When change occurs, the thing we need to keep in mind is how that change affects the website. For example, if someone retires and their contact information is listed dozens or hundreds throughout the website, it's going to take a while to update everything. But this type issue could be avoided. Instead of hard-coding the information everywhere, why not import it using PHP. [Continue reading]