ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-lib
php-lib
Re: [Phplib-users] Select Box!
by Marylly Araujo Silva other posts by this author
Apr 26 2005 10:34AM messages near this date
Re: [Phplib-users] Select Box! | [Phplib-users] Select Box!
Andrew,

I've been using the PHPLIB's database abstraction I guess.
But I doesn't matter if it is PHPLIB's data abstraction or not. I hope a 
combobox which works.
I will try the first example that you have writen and later I write the 
results.

see ya

Marylly
**Mya**


Andrew Crawford wrote:

>  Hi Mya,
> 
>  Are you using PHPLIB's database abstraction?  Are you using PHPLIB 
>  templates?
> 
>  If the answer to these questions is no, you have a general PHP 
>  question and should look for another mailing list or forum to get the 
>  answer.
> 
>  If the answer to both questions is yes, you should be able to do 
>  something like this:
> 
>  function make_select_list($selected) {
>      $exampledb = new DB_Example;
>      $query = "SELECT label,value FROM table ORDER BY label";
>      $exampledb->query($query);
> 
>      // Did we get any results?  If not, fail appropriately ...
> 
>      // Loop template
>      $loop_t = new Template_Example;
> 
>      // our mini-template
>      $loop_t->set_var("option", "<option 
>  value=\"{value}\"{selected}>{label}</option>\n");
> 
>      // put our data into the template
>      while ($exampledb->next_record()) {
>          $loop_t->set_var(array(
>                                 "label" => $exampledb->f("label"),
>                             "value" => $exampledb->f("value"),
>                         "selected" => ((!is_null($selected) and 
>  ($exampledb->f("value") == $selected)) ? " selected" : "")));
>          $loop_t->parse("options", "option", true);
>      }
> 
>      // return the options list
>      return $loop_t->get_var("options");
>  }
> 
>  The returned value will then contain a series of options:
> 
>  <option value="value1">Label 1</option>
>  <option value="value2">Label 2</option>
>  ...
>  <option value="valuen">Label n</option>
> 
>  ... and you can put it into your main page template, assigning it to a 
>  template variable just like anything else.
> 
>  Template:
> 
>  <!-- top part of page goes here -->
>  <select name="example_select">
>    {option_list}
>    </select>
>  <!-- bottom part of page goes here -->
> 
> 
>  Code:
> 
>  // Set selected to appropriate value
>  $selected = "";
> 
>  // Set up your template
>  $t = new Template;
>  $t->set_file('content', 'example_template.ihtml');
> 
>  // Generate the option list
>  $our_option_list = make_select_list($selected);
> 
>  // Fill in the variables
>  $t->set_var('option_list', $our_option_list);
> 
>  // Output the page
>  $t->parse('out', 'content');
>  $t->p('out');
> 
>  I hope that helps.
> 
>  Andrew Crawford
> 
>  Marylly Araujo Silva wrote:
> 
> > hello guys
> >
> > Can I create a select box and create the options using a db query 
> > from the database?
> >
> > thanks
> >
> > Marylly
> > **Mya**
> 
> 





-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id=105hix
_______________________________________________
Phplib-users mailing list
Phplib-users@[...].net
https://lists.sourceforge.net/lists/listinfo/phplib-users

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved