PHP
  Home arrow PHP arrow Page 3 - PHP and JavaScript Interaction: Storing Data in the Client, part 3
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP and JavaScript Interaction: Storing Data in the Client, part 3
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 14
    2005-05-18


    Table of Contents:
  • PHP and JavaScript Interaction: Storing Data in the Client, part 3
  • Records wanted! Fetching data from tables
  • Defining data containers: the "createDivs()" function
  • Showing database records: the "displayRecords()" function
  • 1 - 2 - 3 Next
  • Building paging links: the sequel
  • Building client-based result sets: making PHP and JavaScript interact

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    PHP and JavaScript Interaction: Storing Data in the Client, part 3 - Defining data containers: the "createDivs()" function
    ( Page 3 of 7 )

    Before we start writing the code for the JavaScript functions, it's necessary to initialize a couple of global variables that we need to use at a later time. First, let's specify the number of records to be displayed at a time. For our example, we'll assign a value of 4:

    var recsPage=4;

    Second, let's calculate the number of pages needed to show the paginated records:

    var numPages=Math.round(rows.length/recsPage);

    As you can see, this value is obtained by dividing the total number of elements contained in the "rows" array (rows.length) by the total number of pages. Finally, the result is rounded using the "round" method provided by the JavaScript "Math" object. Okay, our work for the variable setup is now finished. Let's look at the functions.

    To begin with, we'll only need three core functions. The first function, which I've named "createDivs," takes care of creating two <div> containing elements. The first <div> will be used to contain the proper database record values, while the second will hold the paging links. This sounds pretty logical.

    Once we've seen the reason to create this function, let's have a look at its definition:

    createDivs=function(){
      // create records containing <div>
      var recsDiv=document.createElement('div');
      recsDiv.id='records';

      // create paging link containing <div>
      var linksDiv=document.createElement('div');
      linksDiv.id='paginglinks';

      // insert <div> elements into document structure
      document.body.appendChild(recsDiv);
      document.body.appendChild(linksDiv);
    }

    As you can see, the function creates the "recsDiv" <div> element in memory and assigns to it a "records" ID attribute, handy for applying a CSS style. This is the element that will contain record data. Here's the code for the element's creation and ID assignment:

    // create records containing <div>
    var recsDiv=document.createElement('div');
    recsDiv.id='records';

    Next, in a similar way, a second "linksDiv" is generated, tying a "paginglinks" ID to it, suitable for element styling. Obviously, this element will contain the record paging links:

    // create paging link containing <div>
    var linksDiv=document.createElement('div');
    linksDiv.id='paginglinks';

    Once these containers have been created, they are properly inserted in the Web document tree, as follows:

    document.body.appendChild(recsDiv);
    document.body.appendChild(linksDiv);

    I told you that this function was easy to grasp! With this first function defined, our next task is to set up the second one, which is called "displayRecords." Not surprisingly, it will show the records in a paginated way. Let's move on and jump into its source code.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT