>> Is it possible to have a function which echoes the values as they are
>> read from the database?
>
>something like....
>
>function init_auth_list()
> {
>         print "<select name=author> <option value=\"\">select the name of
>the author</option\>";
>         $query="select name from author order by name";
>         $result=pg_exec($GLOBALS["db"],$query);
>         $numrows=pg_numrows($result);
>         $i=0;
>         while($i<$numrows)
>         {
>         $row=pg_fetch_row($result,$i);
>         print "option name=\"".$row[0]."\">$row[0]</option>";
>         $i++;
>         }
>         print "</select>";
> }

Two things with this, and opinions may vary...

Functions shouldn't print or echo anything, rather you should return what is to
be displayed.  Also you may want to clean up/condense your while in the
following manner;

<?PHP
function init_auth_list(){
        $return="<select name=author> <option value=\"\">select the name of the
author</option\>";
        $query="select name from author order by name";
        $result=pg_exec($GLOBALS["db"],$query);
        $numrows=pg_numrows($result);
#       $i=0; moved to while statement
        while($i=0;$i<$numrows;$i++;){
                $row=pg_fetch_row($result,$i);
                $return.="option name=\"".$row[0]."\">$row[0]</option>";
#               $i++; moved to while statement
        }
        $return.="</select>";
        return $return;
}
?>

then print your select box with the following

<?PHP echo init_auth_list(); ?>


much of that is personal preference mind you;

Dave

>> I tried doing something of this sort..but didn't work..
>> Any suggestions?
>> Thanks in advance,
>> Mukta
>>
>
>hope it works, this is just from the top of my head...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to