Table of Contents
循环出来的Select选项问题
Jun 23, 2016 pm 02:22 PM
select php
选择月份: <select name="month"> <?php for($i="1"; $i<="12"; $i++){ if($i<10){ echo "<option>0".$i."月</option><br>"; }else{ echo "<option>".$i."月</option><br>"; } } ?> </select>
Copy after login
这个月份是通过For循环出来的,默认是选择1月份,当选择其它月份再点提交后,又显示回1月份了,有什么办法可以停留在当前选择的月份呢?
回复讨论(解决方案)
这样写
<select name="month"><?php $m = 5; // 假定选中的是 5 月for($i="1"; $i<="12"; $i++){ printf("<option value=%d %s>%02d月</option>", $i, $m == $i ? ' selected' : '', $i);}?></select>
Copy after login
Copy after login
Copy after login
这样写
<select name="month"><?php $m = 5; // 假定选中的是 5 月for($i="1"; $i<="12"; $i++){ printf("<option value=%d %s>%02d月</option>", $i, $m == $i ? ' selected' : '', $i);}?></select>
Copy after login
Copy after login
Copy after login
我选择8月,点提交后怎么又回到5月了??
你难道不赋值吗?
你难道不赋值吗?
谢谢,value=%d %s>%02d月 这一句是什么意思呢?
这样写
<select name="month"><?php $m = 5; // 假定选中的是 5 月for($i="1"; $i<="12"; $i++){ printf("<option value=%d %s>%02d月</option>", $i, $m == $i ? ' selected' : '', $i);}?></select>
Copy after login
Copy after login
Copy after login
选择仓库: <select name="depot"> <?php $ckSQL = "SELECT MC001,MC002 FROM {$dataBase}CMSMC"; $ckQuery = sqlsrv_query($conn,$ckSQL); if( $ckQuery === false) { die( print_r( sqlsrv_errors(), true) ); } $ck = $_POST["depot"]; while($ckRow = sqlsrv_fetch_array($ckQuery)) { //echo "<option>".$ckRow[1]."</option>"; printf("<option >%s</option>", $ckRow[1], $ck == $ckRow[1] ? ' selected' : '', $ckRow[1]); } sqlsrv_free_stmt( $query); ?> <option value="全部" <?php if($_POST["depot"] == "全部"){echo 'selected="selected"';} ?>>全部</option> </select>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
