PHPBuilder - Arrays, HTML and PHP



RSS Twitter
Articles Html

Arrays, HTML and PHP

by: Tim Perdue
|
July 30, 2000

Sorry I haven't updated PHPBuilder is SO long, but I've been a bit busy helping build a new web site called SourceForge. While building the site, I stretched my knowledge of PHP and databases and thought I would share a few things I learned.
A lot of people ask about passing arrays and using checkboxes/select boxes in PHP, so that's what I'll cover today.
To pass multiple values, as in a "Multiple Select Box", put [] after the variable name, like assigned_to[].
<SELECT NAME="assigned_to[]" MULTIPLE SIZE="8">
    <OPTION VALUE="100">None</OPTION>
    <OPTION VALUE="2">dtype</OPTION>
    <OPTION VALUE="4">tim_perdue</OPTION>
    <OPTION VALUE="5">fusion94</OPTION>
    <OPTION VALUE="3">precision</OPTION>
    <OPTION VALUE="18">michael</OPTION>
    <OPTION VALUE="157">jbyers</OPTION>
    <OPTION VALUE="251">Lectric</OPTION>
    <OPTION VALUE="149">baddog</OPTION>
    <OPTION VALUE="105">mrzenn</OPTION>
</SELECT>
Then on the receiving page, you simply do a count() on assigned_to, and iterate through the list of values that was selected.

<?php

$count
=count($assigned_to);

for (
$i=0$i<$count$i++) {
    echo 
$assigned_to[$i];
}

?>

1
|
2
|
3
|
4
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Tim Perdue

Comment:



Comment:

(Maximum characters: 1200). You have characters left.