Archive for July, 2011

July 26th, 2011  Posted at   Education Web Design
   |   Comments Off

Efficient SQL Databases

Don’t be fooled by seeming simplicity. A lot of developers get comfortable with a certain way of designing a database for their web applications that they miss out on techniques they should rather employ to make things run faster and more efficiently. A lot of developers don’t bear in mnd that the small site they are creating now might grow into something incredibly large and complex, and the database they designed has become bloated and doesn’t scale well to meet the demands of the increased traffic.

This article hopes to provide web developers with a few techniques to help make their database and queries faster and more efficient.

1. Avoid Character Types

When you are designing a database, it is so easy to set all data types to the VARCHAR type as it can then contain any data you want; numbers or text. But character data is amongst the most inefficient data type you can get.

If a field is only going to contain numbers, then make it one of the appropriate types (INT, DOUBLE, etc).

Also, wherever possible in your web development code, try to use numeric data types as opposed to characters. One of the most common things a script has to store are flags like whether someone answered yes or no to a question, etc. You could of course store it as ‘Y’ or ‘N’ but why not store it as 0 and 1?

The reason this makes a difference is when you have a database, for example, with over 500 000 entries, and are running a SELECT on that field, comparisons are processed a lot faster for numeric data types than character types. Also, if you need to return data to the calling script, numeric data is less memory intensive than character data.

In addition, your web development language (PHP, ASP, etc) would also be able to process and perform functions on numeric data better than character data.

I am not trying to convince you never to use character data types. Sometimes it is a necessity, but if you can find ways to reduce the amount of character data processed by your SQL database, the better your server will cope.

2. Normalization

Normalizing a database is really quite a complex process. It is a process that describes a way to design a database structure to avoid repetition of data in your database and can lead to significant performance benefits if employed correctly. However, the entire process of normalisation is a bit beyond the scope of this article as it can fill books on its own, but any developer designing a database should seriously consider becoming knowledgable about normalisation and employing it in their own designs.

For a good tutorial on this process: http://www.keithjbrown.co.uk/vworks/mysql/mysql_p7.php

3. DateTime vs Timestamp fields

This actually relates to 1. a bit. The big difference to bear in mind here is that a field of type DATETIME is actually stored as a series of characters. A field of type TIMESTAMP is actually stored as an integer. So therefore, a more efficient way of storing dates is using the timestamp method. The timestamp has its drawbacks however. For one, you cannot store a date early than 1 January, 1970. Also, timestamps in your script will need recalculating to get to the character format. Because of this recalculation, it may not be better to store as timestamp. It really is a case of testing which format works better for your needs.

4. Use LIMIT where possible

In your queries, if you are doing a SELECT to a database and you only expect a certain number of results, using the LIMIT statement can speed your query up incredibly.

For example, if you have a table of users and you need to run a query to search for one users record, you can use a query like:

SELECT user_name FROM users WHERE user_id = 453;

This query is perfectly valid and will return the right result. But you also know there will only be ONE result. The query above will search the database, find what you want, but then still continue searching after that. It would run a lot faster if you could tell the query that once it has found what you are looking for to stop searching. LIMIT can do this, as this query shows:

SELECT user_name FROM users WHERE user_id = 453 LIMIT 1;

Imagine this scenario. You have a table called logins, that records every login from a user. It currently contains over 2 000 000 records, and you want to find the first time a user logged in. Now bear in mind that because this table inserts data over time, it is already sorted for by date. You could do the following query:

SELECT MIN(login_date) FROM logins WHERE user_id = 4876;

This will return the record you want, but SQL will now have to get all dates for that user, sort them and then return the lowest value to you. Our table is already date sorted simply because of the way it records data for us. So using LIMIT can be more effective:

SELECT login_date FROM logins WHERE user_id = 4876 LIMIT 1;

Because it is sorted, the first one will always be a users first login.

5. Avoid using LIKE

If you have tried to employ 1. above, then hopefully you will be in a scenario where you do not need to use LIKE all that much. LIKE is one of the most inefficient ways of searching a table. LIKE performs a text comparison search in a field and with no wildcards is as efficient as a direct comparison; i.e. WHERE name = ‘Jane’ is equivalent to WHERE name LIKE ‘Jane’. It is when you start introducing the wildcard characters like ‘%’ that things get really hairy.

If you do have to use LIKE, then at least try and make efficient use of the wildcards. These are ‘_’ (underscore) and ‘%’. Let me explain all this with a real world example.

In a project I was involved in, we had a SQL database storing logs generated automatically from a mail server. Unfortunately, the mail server pretty much just dumped a very long string of text data into a field that contained the data we wanted. A script had to be written to find all logs that referred to a login by a user into the POP server. The only way we could do this was to search every record for a string in the msg field that had the text “User logged in” in it. The first query developed was something like this:

SELECT msg FROM logs WHERE msg LIKE ‘%User logged in%’;

This query took on average of about 35 minutes to process. Obviously not an ideal situation. The way the LIKE worked here was that it had to parse through every single portion of each and every record in the msg field looking for text that matched “User logged in” anywhere in the text. We were able to determine eventually that the text “User logged in” occured at the end of that text in the msg field and so we altered the query:

SELECT msg FROM logs WHERE msg LIKE ‘%User logged in’;

The ‘%’ at the end was removed as we do not want to worry about text after because there is none. The query now only compares text to our string in the msg field at the end of the field and no longer parses through the entire piece of text stored in msg. The query now ran in under 2 minutes. (This was actually still too long, but how we optimised from there is a little beyond the scope of this articl

 

Now Pay Close Attention –

Making money online with e-commerce is simpler than you’ve been told. Everyone faces the same two problems:

[Problem #1] How To Get Your Online Store Started

[Problem #2] How To Bring Traffic To Your Store To Produce Sales

ZamZuu has been solving these two problems for thousands of people! ZamZuu has been tried and tested and known to produce excellent results.

First: Visit ZamZuu Here
Learn How Your Can Start Your Own E-Commerce Store For Next To Nothing and Make THousands Monthly Using Our Proven Secrets!

Second: Sign Up For More Information From ZamZuu
We will show you exactly how you can start your e-commerce store and begin making profits online in as little as 7 days!

With over 2 Billion dollars being spend on e-commerce this year alone, online sales are a massive opportunity to make a great living online. But to take advantage of this amazing opportunity, it is always a good idea to get a head start on your competition with the help of a company that has been doing it for years. Visit http://www.takeforeveroff.com and learn how you can make a great living in e-commerce.

July 25th, 2011  Posted at   Education Web Design
   |   Comments Off

Correct HTML Usage in Web Project

Proper use of html is the key to getting maximum flexibility and return on your investment in web content. From its earliest origins, html was designed to distinguish clearly between a document’s hierarchical outline structure (Headline 1, Headline 2, paragraph, list, and so on) and the visual presentation of the document (boldface, italics, font, type size, color, and so on). html markup is considered semantic when standard html tags are used to convey meaning and content structure, not simply to make text look a certain way in a browser.
This semantic approach to web markup is a central concept underlying efficient web coding, information architecture, universal usability, search engine visibility, and maximum display flexibility. Web content is accessed using web browsers, mobile computing devices of all kinds, and screen readers. Web content is also read by search engines and other computing systems that extract meaning and context from how the content is marked up in html.
Search engine would be able to distinguish the importance and priority of the headlines, discover which keywords were important, and identify conceptually related items in list form.

A Cascading Style Sheet designed particularly for mobile phones could display the headlines and text in fonts appropriate for small screens, and a screen reader would know where and how to pause or change voice tone to convey the content structure to a blind reader.
Properly structured html (or xhtml) documents may contain the following elements:
• html document structure (
, ,
, )
• Text content
• Semantic markup to convey meaning and content structure (headlines, paragraph text, lists, quotations)
• Visual presentation (css) to make content look a certain way
• Links to audiovisual content (gif, jpeg, or png graphics, QuickTime or other media files)
• Interactive behavior (JavaScript, Ajax elements, or other programming techniques)
In properly formed html, all web page code is contained within two basic elements:
• Head (…)
• Body (…)
In the past these basic divisions in the structure of page code were there primarily for good form: strictly correct but functionally optional and invisible to the user. In today’s much more complex and ambitious World Wide Web, in which intricate page code, many different display possibilities, elaborate style sheets, and interactive scripting are now the norm, it is crucial to structure the divisional elements properly. Style Sheets allow web publishers to retain the enormous benefits of using semantic html to convey logical document structure and meaning while giving graphic designers complete control over the visual display details of each html element. css works just like the style sheets in a word-processing program such as Microsoft Word. In Word, you can structure your document with ranked headlines and other styles and then globally change each one just by changing its style. css works the same way, particularly if you use linked external style sheets that every page in your web site shares. Correct Html Usage makes your site approved by www3 and that is one of the main factors Google consider for Page Ranking. For more Information Please check” www.seosolutionindia.co.in” a chandigarh SEO company.