Technology computers-hardware

How to Do Client Server Coding

    • 1). Create the data for your website. Normally this data will be stored in a database, and there are free Web database systems available such as MySQL. Find out what provision your Web host makes for database systems and set up a database to hold whatever data you need for your site content. In most cases, Web hosts provide an automated interface such as "phpMyAdmin" for database creation with no requirement for programming code.

    • 2). Write server side code to connect to your database and query it using SQL, as in the following PHP example:

      <?php

      //connect to the database

      mysql_connect("enter_host", "enter_username", "enter_password");

      mysql_select_db("enter_database_name");

      //query

      $example_query="SELECT someField FROM SomeTable";

      ?>

      Alter the parameters in the code to suit your own database name and structure in the areas labeled "enter host," "enter username," "enter password" and "enter database name." Save your PHP scripts with ".php" extension.

    • 3). Build HTML structures into the PHP code to create your web-pages, as follows:

      $example_result=mysql_query($example_query);

      //go through your results

      while($example_row=mysql_fetch_array($example_result))

      { echo "<p>".$example_row['someField']."</p>"; }

      This code writes out the value of a specified row in a database table inside an HTML paragraph element, repeating this until each row in the table has been written to the page.

    • 4). Add client side code to your pages to enhance the user experience of viewing your site, as in the following example. Before the "<?php" line:

      <html>

      <head>

      <script type="text/javascript">

      function overParagraph(parID)

      { document.getElementById(parID).style.color="#FF0000"; }

      </script>

      </head>

      <body>

      Change the "while" loop to the following:

      $counter=0;

      while($example_row=mysql_fetch_array($example_result))

      { echo "<p id='p".$counter."' onmouseover='overParagraph(this.id)'>".$example_row['someField']."</p>"; $counter++; }

      Add after the closing "?>" line:

      </body>

      </html>

      This simple example changes the color of the paragraphs when the visitor rolls their mouse over them.

    • 5). Upload the scripts and web-pages to your Web server. Test your site by visiting each page and check that it behaves in the way you need it to. If there are problems or you see error messages when you attempt to view the pages, check to ensure all of the code has been structured correctly. Make changes to the code one at a time, testing again each time you make a change until the site behaves correctly.

Related posts "Technology : computers-hardware"

Is There a Way to Recover Data From an S RAM Card?

Hardware

How to Create a DVD With More Than One Video File Separated Into Titles

Hardware

How to Troubleshoot Your Dell Notebook With a Projector

Hardware

Printing On A Constant Progression

Hardware

Tips on Using a Digital Pen Efficiently

Hardware

How to Fix a Master Boot Record in Vista Ultimate

Hardware

Setting Up a PC as a Wireless Router

Hardware

How to Upgrade a MacBook

Hardware

How to Disable the Touch Pad on a Dell Precision M90 Laptop

Hardware

Leave a Comment