Introduction to the html_options method in smarty

Source: Internet
Author: User
The html_options method in smarty generates a select drop-down list in the template, which id can be initialized to be selected. See the following code: the html_options method in the php part of smarty generates a select drop-down list in the template, which id can be initialized to be selected? See the following code:
Php section
$ SQL _sysuser = "select * from tuser where tuser_status = '1' order by tuser_truename ";
$ Rs_sysuser = $ db-> SQL _query ($ SQL _sysuser );
While ($ row_sysuser = $ db-> SQL _fetchrow ($ rs_sysuser )){
$ Usersys [$ row_sysuser ['tuser _ name'] = $ row_sysuser ['tuser _ truename'];
}
Html section
<{Html_options options = $ sysUser}>

It can be seen that the html_options of smarty actually accepts an array, and this array still requires dropping ~
The key value of the array will be the value of option, and the value of the array will be the value of option. if you need to set a value in the initial status to the selected status

Procedure
$ Smarty-> assign ('customer _ id', 1001 );

Template
{Html_options options = $ cust_options selected = $ customer_id}

Html_options also has a usage. The value of option is separated from the display, so that you can easily handle other situations.
The usage is as follows:
Index. php:

Require ('smarty. class. php ');
$ Smarty = new Smarty;
$ Smarty-> assign ('cust _ id', array ));
$ Smarty-> assign ('cust _ names', array ('Joe schmoe', 'Jack Smith ', 'janejohnson', 'carlie Brown '));
$ Smarty-> assign ('customer _ id', 1001 );
$ Smarty-> display ('index. tpl ');

Template index. tpl:
{Html_options values = $ cust_ids selected = $ customer_id output = $ cust_names}
Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.