English 中文(简体)
保留选项箱的价值
原标题:Remembering the value of a option box
  • 时间:2011-06-24 13:19:16
  •  标签:
  • php

下面的法典产生了一个动态的下降箱。

<select name="parent">
    <?php 
    $q = $admindb->getParentCategories();
    while($row=mysql_fetch_assoc($q)){
        $title=$row[ title ];
        $catid=$row[ id ];
        ?>
        <option value="<?php echo $catid; ?>"><?php echo $title; ?></option>
        <?php
    }   
    ?>
</select>

However, if the form is returned to the user with validation errors, I need the box to remember the previous selection..

在使用文字箱时,我使用了以下代码来纪念这一条目。

<input type="text" name="title" value="<?php echo $form->value("title"); ?>">

我如何在选定的法典中添加这种价值标签?

增 编

最佳回答

修改<条码>。 内容提要

<option value="<?php echo $catid; ?>"<?php if($catid == $form->value("fieldname") echo  selected="selected" ; ?>><?php echo $title; ?></option>
问题回答

You have to use the selected attribute:

    <option value="<?php echo $catid; ?>"
        <?php if ($_GET[ parent ] === $catid): echo  selected ?>><?php echo $title; ?></option>

如你写X维吾尔文,请使用<代码>,选择=”<>。

您需要将<条码>选择=“true”添加到相应的正确选择中:

<select name="parent">
    <?php 
    $q = $admindb->getParentCategories();
    while($row=mysql_fetch_assoc($q)){
        $title=$row[ title ];
        $catid=$row[ id ];
        ?>
        <option value="<?php echo $catid; ?>" <?php if ($catid == $form->value("title")) { echo   selected="true" ;} ?>><?php echo $title; ?></option>
        <?php
    }   
    ?>
</select>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签