php 如何让select 被选中
各位高手,我是个初学者,最近做php时,从数据库得的数不能在 页面显示,请帮忙,非常感你们。
过程如下:
mysql 数据库中一个表为 school_grade
内容如下:
gradeId gradeName gradeState
2012 12级 毕业
2013 12级 在校
下面用的是smaryt
1 model层为:
class manaModel
{
public function showGrade(){
//这是用于显示年级的
$sqlHelper=new SqlHelper();
$sql="select * from school_grade";
$result=$sqlHelper->execute_selectArray($sql);
$sqlHelper->close_connect();
return $result;
}
}
2 控制层为:
require_once '../models/manaModle.class.php';
$dataModel=new manaModle();//实例 化用户模板
$smarty->assign("res_grade",$dataModel->showGrade());//用于显示年级
$smarty->display("manager.html");
?>
3 view(templates)层:
年级设置
年级编号 | 年级名称 | 年级状态 |
|
我想在显示表格中,有一个select 中,12级为毕业,那就显示为“毕业”,13级人在校,select 中选中"在校",同时,内部的两种状态还存在,请况代码如何写,用javascript也可以,请帮外忙,我将非常感激。
回复讨论(解决方案)
不知道smaryt的标签怎么用 先试试吧
不明白你的意思,选中的标准是什么?
在需要选中的option上加入
例如
这种方法我试过了,不能根据$mess.gradeState的值来判断哪个值被选中,执行结果都为‘毕业’,
但也非常感谢了。
这种方法我试过了,不能根据$mess.gradeState的值来判断哪个值被选中,执行结果都为‘毕业’,
但也非常感谢了。
为什么两个option的value都是{$mess.gradeState},这里有问题吧,另外你说不能根据$mess.gradeState的值来判断哪个值被选中,这就奇怪了,可以这样测试
echo $mess.gradeState;
var_dump($mess.gradeState=='在校');
看看输出什么。
这种方法我试过了,不能根据$mess.gradeState的值来判断哪个值被选中,执行结果都为‘毕业’,
但也非常感谢了。
那你打印$mess.gradeState出来看下是什么
这种方法我试过了,不能根据$mess.gradeState的值来判断哪个值被选中,执行结果都为‘毕业’,
但也非常感谢了。
那你打印$mess.gradeState出来看下是什么
在控制层打印如下:
Array
(
[0] => Array
(
[gradeId] => 127
[gradeName] => 13级
[gradeState] => 在校
)
[1] => Array
(
[gradeId] => 127
[gradeName] => 12级
[gradeState] => 毕业
)
)
但是,在view层 ";?>打印不出结果。用 一句在页面的打印出的结果为:在校 毕业
{$mess.gradeState}能分别输出 在校和毕业是吗
那用6楼的var_dump($mess.gradeState=='在校'); 看看是不是boolean类型 是不是true
{$mess.gradeState}能分别输出 在校和毕业是吗
那用6楼的var_dump($mess.gradeState=='在校'); 看看是不是boolean类型 是不是true
不能输出,显示不出boolean 类型。
这是不因我用的是smarty模板的原因啊,因为整个操作都在 teplates中进行了,按理说,smaryt应该是显示与逻辑分开的,我在显示是用了逻辑,请高手指点一下。这种情况如何解决。
充填 option,smarty 有专门的方法 http://www.111cn.net/phper/122/smarty_html_options_select.htm
充填 option,smarty 有专门的方法 http://www.111cn.net/phper/122/smarty_html_options_select.htm
这几天我一直研究这个问题,但总找不到如何进行判断。
问题没有解决,含泪感谢大家。
请大家继续到这个地文坛帮我:
http://blog.csdn.net/yuxuefa/article/details/39855827

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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











PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
