PHP
  Home arrow PHP arrow Page 8 - PHP 101 (part 3) - Chocolate Fudge And Time Machines
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 101 (part 3) - Chocolate Fudge And Time Machines
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2000-08-15


    Table of Contents:
  • PHP 101 (part 3) - Chocolate Fudge And Time Machines
  • Back To The Future
  • Revisiting The Past
  • Doing It By The Numbers
  • Anyone For Apple Pie?
  • The Generation Gap
  • What's That Noise?
  • Checking The Boxes
  • Miscellaneous Notes

  • 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 101 (part 3) - Chocolate Fudge And Time Machines - Checking The Boxes
    ( Page 8 of 9 )

    In addition to their obvious uses, arrays and loops also come in handy when processing forms in PHP. For example,

    Here's a simple example which demonstrates how arrays can be used when processing checkboxes in an HTML form:

    <html> <head> </head> <body> <? // check for $submit if (!$submit) { // and display form ?> <form action="jukebox.php4" method="GET"> <input type="checkbox" name="artist[]" value="Bon Jovi">Bon Jovi <input type="checkbox" name="artist[]" value="N'Sync">N'Sync <input type="checkbox" name="artist[]" value="Boyzone">Boyzone <input type="checkbox" name="artist[]" value="Britney Spears">Britney Spears <input type="checkbox" name="artist[]" value="Jethro Tull">Jethro Tull <input type="checkbox" name="artist[]" value="Crosby, Stills & Nash">Crosby, Stills & Nash <br> <input type="submit" name="submit" value="Select"> </form> <? } // or display the selected artists else { ?> <b>And here are your selections:</b> <br> <? // use a "for" loop to read and display array elements for($count = 0; $count < sizeof($artist); $count++) { echo "<i>$artist[$count]</i><br>"; } } ?> </body> </html>
    In this case, when the form is submitted, PHP will automatically create an array variable named $artist, and populate it with the items selected. This is useful when you need to group related form data together.

    The same technique can be applied to "multiple select" list boxes:


    <html> <head> </head> <body> <? // check for $submit if (!$submit) { // and display form ?> <form action="jukebox.php4" method="POST"> <select name="artist[]" size="6" multiple> <option value="Bon Jovi">Bon Jovi</option> <option value="N'Sync">N'Sync</option> <option value="Boyzone">Boyzone</option> <option value="Britney Spears">Britney Spears</option> <option value="Jethro Tull">Jethro Tull</option> <option value="Crosby, Stills & Nash">Crosby, Stills & Nash</option> </select> <br> <input type="submit" name="submit" value="Select"> </form> <? } // or display the selected artists else { ?> <b>And here are your selections:</b> <br> <? // use a "for" loop to read and display array elements for($count = 0; $count < sizeof($artist); $count++) { echo "<i>$artist[$count]</i><br>"; } } ?> </body> </html>


     
     
    >>> More PHP Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
     

       

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek