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? 
Google.com  
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

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek