Posts Tagged ‘contain’

Why Use a Database?

Tuesday, September 30th, 2008

Databases are most useful when it comes to storing information that fits into logical categories. For example, say that you wanted to store information of all the employees in a company. With a database you can group different parts of your business into separate tables to help store your information logically. Example tables might be: Employees, Supervisors, and Customers. Each table would then contain columns specific to these three areas. To help store information related to each employee, the Employees table might have the following columns: Hire, Date, Position, Age, and Salary.

PHP:Use Less PHP And More HTML With Alternative Syntax

Monday, June 30th, 2008

When PHP is tightly intertwined with HTML it can be awful to lay your eyes upon. Many years ago, while with a previous employer, the development staff and I believed it was a sin to use straight HTML in PHP files. We believed every file ending in a .php extension could only contain PHP. In retrospect, I don’t know why we ever did this, but I have seen other groups adhere to such rules as well. This style made what should have been simple HTML far more complex that it had to be.

Over the past few years the style in which developers are writing PHP to output HTML has shifted quite a bit.

Example 1: No Alternative Syntax, and a Lot of PHP.

<?php
echo “<table size=\”100\”>\n”;
echo ” <tbody>\n”;

if($displayResults) {

while($row = mysql_fetch_assoc($result)) { ?>
echo “<tr>\n”;
echo “<td>” . htmlentities($row['id']) . “</td>\n”;
echo “</tr>\n”;
}

}

echo “</tbody>\n”;
echo “</table>\n”;

?>

This is typical to what I’ve seen in a number of PHP applications. Though this is a simple example, I am sure you can appreciate how this method of outputting mostly html can grow out of control. It requires significantly more developer brain power to determine the code’s purpose than the example below.

Example 2: Less PHP Paired With Alternative Syntax

<table>
<tbody>
<?php if($displayResults): ?>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><?php echo htmlentities($row['id']); ?></td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>

Here in example 2 the same functionality is achieved by using PHP alternate syntax and less output statements. As you can see, this fashion of interweaving PHP and HTML can go a long way to increase code readability.

SEO : Use Title and ALT Attributes

Thursday, June 26th, 2008

More often then not, web addresses (URL’s) do not contain the topic of the page. For example, the URL www.myspace.com says nothing about being a place to make friends. Where a site like www.placetomakefriends.com would tell Google right away that the site being pointed to is about making friends. So to be more specific about where we are pointing to in our links we add a title attribute and include our keywords.

Using the Title Attribute is an direct method of telling the search engines about the relevance of the link. It’s also a W3C standard for making your page accessible to disabled people. In other words, blind folks can navigate through your website using a special browser that reads Title and ALT attributes. The syntax is:

<a href=”http://www.top10seotips.com/seo_software.htm” title=”SEO Software”>SEO Software</a>

The ALT Attribute is used for the same reasons as the Title Attribute, but is specifically for describing an image to the search engine and to the visually disabled. Here’s how you would use ALT in an IMG tag:

<img src=”http://top10seotips.com/img/image01.jpg” alt=”Top 10 SEO Tips”>