Creating Dynamic Website Content with PHP - MySQL

Written by Don Beavers


Continued from page 1

Once you have completed these two steps you will have a table compete with data to be shown on your website.

Another option would be to utilize your existing product table. If there are hundreds of different models and styles of widgets already in one ofrepparttar tables in your database, you could utilizerepparttar 142070 same structure we are learning now to connect directly to that table and displayrepparttar 142071 already existing data.

Step two: Working with your new table:

For dynamic content displays to function there must be a mechanism in place that instructs your web page as to which item should be shown to repparttar 142072 visitor. These mechanisms vary in complexity from extremely simple commands torepparttar 142073 more complicated use of cookies or IP tracking to determine which item should be displayed.

For this tutorial, we will utilize one ofrepparttar 142074 most effective mechanisms and perhapsrepparttar 142075 easiest to incorporate. This isrepparttar 142076 use of a random number generator for deciding which item will be shown.

To create a random number generator using PHP you must first calculate repparttar 142077 total number of possible items that you wantrepparttar 142078 system to choose from. In this example we had five items sorepparttar 142079 maximum number of choices will be 5. The reason we need this number is to limitrepparttar 142080 random numbers being delivered. If we have five items, we wantrepparttar 142081 number generator to only give us a result of between 1 and 5.

We must now create a variable for our PHP code that will hold our new randomly generated item number as follows:

$mynumber = rand(1, 5);

This little snippet of code will act asrepparttar 142082 mechanism to “select” a widget product item at random fromrepparttar 142083 five provided inrepparttar 142084 content table that we created.

If we created 100 different items for your dynamic display instead of just five, you would simply changerepparttar 142085 “rand (1, 5)” part ofrepparttar 142086 code to reflectrepparttar 142087 different maximum number. In this case we would change it to “rand (1, 100)” so thatrepparttar 142088 random number generator gives us back a number somewhere between one and one hundred.

We are now ready to extractrepparttar 142089 randomly selected item’s information from your table so that it can be displayed on your webpage.

You can now connect to your database and query your table to findrepparttar 142090 data forrepparttar 142091 item that matchesrepparttar 142092 random number you created, as follows:

$query_content = "SELECT * FROM content_table WHERE item = $mynumber ";

Step three: Displaying your data:

When displaying your data it is important to maintain consistency in presentation size. It is preferable to create a table of specified dimensions (such as “width=400”) and display your results within this table. In this wayrepparttar 142093 page proportions do not have to change with each new item (which can be very confusing for visitors).

Simply displayrepparttar 142094 results just as if these where any other MySQL query usingrepparttar 142095 echo command:

echo $query_content['product'];

Every time your page is loaded a different widget product will be selected at random for display on that page.

What else can you do with your dynamic content?

The only limits are within your imagination. By adding a title and meta description tags to your content table, you can alternaterepparttar 142096 title and search engine description for that page. You can also utilize this system to promote affiliate programs or sponsorship opportunities by rotating affiliate links and banners.

The proper use of dynamic content can bring your website back into favor with search engines and encourage your visitors to return frequently to see what is new.

Don Beavers lives in Bryan, Texas and is an enterprise level PHP-MySQL programmer at the Datavor Web Directory and at the Shopping Elf directory Shopping Guide


How To Start An Internet Business – Designing For Usefulness

Written by Halstatt Pires


Continued from page 1

What about a product site? Let’s use Nomad Journals – http://www.nomadjournals.com - as our example. The site sells writing journals for outdoor activities such as hiking, travel, rock climbing, etc. The site is simple, clean and loads fairly quickly. Unlike Google,repparttar site immediately needs to convey an outdoor impression to visitors. This is accomplished with three outdoor images, a graphic of a “nomad” and images ofrepparttar 142027 journals. The text is keyword dense, but compact and torepparttar 142028 point. The page conveysrepparttar 142029 nature ofrepparttar 142030 product andrepparttar 142031 “vibe” ofrepparttar 142032 business.

Onrepparttar 142033 other end ofrepparttar 142034 spectrum, consider an entertainment site such as American Idol – http://www.idolonfox.com. The site is slick, offers polls and has community message boards where fans can post messages aboutrepparttar 142035 competition. This is a very good layout for this site, but would be horrible for Google or Nomad Journals.

Don’t Rush

Fromrepparttar 142036 above examples, you can see that there is no universally correct design for a site. Before charging off to build a site, spend at few days considering what it should look like and WHY. Visit sites that you use frequently. Why do you keep going back? What annoys you about other sites? How do these factors translate to your site?

Once you haverepparttar 142037 answers, you will be on your way.

Halstatt Pires is with Marketing Titan- an Internet marketing and advertising company comprised of a search engine optimization specialist providing meta tag optimization services and Internet marketing consultant providing internet marketing solutions through integrated design and programming services.


    <Back to Page 1
 
ImproveHomeLife.com © 2005
Terms of Use