#native_company# #native_desc#
#native_cta#

Arrays, HTML and PHP Page 2

By Tim Perdue
on July 30, 2000

Easy, right? Instead of echoing the values, you can insert them into a database or
do whatever you need to do.
Over the past year, I’ve created a bunch of utilities that help me code faster. Utilities
that create HTML select boxes, multiple select boxes (as shown above), show database results, etc.
Here’s the first. It takes a two-column database result and creates a pop-up box from it.
Notice how I use apostrophes instead of quotes. This helps improve speed of parsing.

<?php

function build_select_box ($result$name$checked_val="xzxz") {

    
/*

        Takes a result set, with the first column being the "id" or value

        and the second column being the text you want displayed

        The second parameter is the name you want assigned to this form element

        The third parameter is optional. Pass the value of the item that should be checked

    */

    $rows=db_numrows($result);

    echo 
'<SELECT NAME="'.$name.'">';

    for (
$i=0$i<$rows$i++) {

        echo 
'

            <OPTION VALUE="'
.db_result($result,$i,0).'"';

        if (
db_result($result,$i,0) == $checked_val) {

            echo 
' SELECTED';

        }

        echo 
'>'.db_result($result,$i,1).'</OPTION>';

    }

    echo 
'

        </SELECT>'
;

}

?>