doufei6456 2019-02-27 20:27
浏览 21

两个非常相似的<select>,一个不保存到DB?

HTML:

(Some context first, the snipped I am about to share below this is within a loop. This is the loop, and it's based on data from the index file):

<?php
            foreach ($field_data[$i] as &$field) {                  
                $field_name = $field[0];
                $table = $field[1];
                $table_field_name = $field[2];
                $field_type = $field[3];
                $iteration = $field[4];
                $clean = ($iteration >= 0 ? $clean[$table][$iteration][$field_name] : $clean[$table][$field_name]);

... The code snippet that is causing me issues:

                                        <!-- Countries -->
                                    <?php } else if ($field[5] == 'country') { ?>
                                    <select class="select" id="<?php $field_name ?>" name="<?= $table_field_name ?>" <?php if ($required_fields[$table][$i][$field_name] != null  || $required_fields[$table][$field_name] != null) { ?> required <?php } ?> >
                                            <option value=""></option>
                                            <?php foreach ($select['countries_all'] as $dropdown_field) { ?> <!-- This is defined in pd_request_form.php -->
                                                <!-- Country -->
                                                <?php if ($field_name == 'country_id') { ?>
                                                        <option value="<?php echo $dropdown_field['country_id']; ?>" <?php if ($dropdown_field['country_id'] == $clean) { ?>selected<?php } ?>><?php echo $dropdown_field['country_name']; ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                    </select>   
                                    <?php  } else if ($field[5] == 'citizenship_country') { ?>
                                    <select class="select" id="<?php $field_name ?>" name="<?= $table_field_name ?>" <?php if ($required_fields[$table][$i][$field_name] != null  || $required_fields[$table][$field_name] != null) { ?> required <?php } ?> >
                                            <option value=""></option>
                                            <?php foreach ($select['citizenship_countries_all'] as $dropdown_field) { ?> <!-- This is defined in pd_request_form.php -->
                                                <!-- Citizenship Country -->
                                                <?php if ($field_name == 'pd_citizenship_country_id') { ?>
                                                        <option  value="<?php echo $dropdown_field['country_id']; ?>" <?php if ($dropdown_field['country_id'] == $clean) { ?>selected<?php } ?>><?php echo $dropdown_field['country_name']; ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                    </select>   
                                    <?php } ?>

PHP Index file:

        $tab[$i][15] = array("pd_citizenship_country_id","c_pd", "c_pd[$i][pd_citizenship_country_id]","select", $i, 'citizenship_country');
        $tab[$i][16] = array("pd_dietary_restrictions", "c_pd", "c_pd[$i][pd_dietary_restrictions]","textarea", $i);

Select defined here in the same index file:

        // Countries
        $select['countries_all'] = $c_lookup->getCountriesSelect(TRUE);
        $select['countries_current'] = $c_lookup->getCountriesSelect(FALSE);

        // Countries
        $select['citizenship_countries_all'] = $c_lookup->getCountriesSelect(TRUE);
        $select['citizenship_countries_current'] = $c_lookup->getCountriesSelect(FALSE);

Lookup file:

/**
 * Get Countries Select
 *
 * Returns the countries array for use in the countries select drop-down.
 */
function getCountriesSelect($param_all=FALSE, $format='HTML')
{
    $sql;
    $result = FALSE;

    if ($format == '')
    {
        $format = 'HTML';
    }

    $sql = "SELECT country_id, country_name, country_order
            FROM c_country
            WHERE country_status_id = 'A' ";
            if (!$param_all)
            {
                $sql.= "AND country_current_b = 'Y' ";
            }
    $sql.= "ORDER BY country_order, country_name";

    $result = $this->c_db->Execute($sql);

    if ($result)
    {
        $countries = array();

        $country_order = '';
        while (!$result->EOF)
        {
            $row = array();
            $row_html = array();
            $row = $result->FetchRow();
            if ($format == 'HTML')
            {
                $row_html['country_id'] = htmlentitIes($row['country_id'], ENT_QUOTES, $this->html_encoding);
                $row_html['country_name'] = htmlentitIes($row['country_name'], ENT_QUOTES, $this->html_encoding);
                $row_html['country_order'] = htmlentitIes($row['country_order'], ENT_QUOTES, $this->html_encoding);
            }
            else
            {
                $row_html['country_id'] = $row['country_id'];
                $row_html['country_name'] = $row['country_name'];
                $row_html['country_order'] = $row['country_order'];
            }
            $countries[] = $row_html;
        }
    }
    else
    {
        error_log("ERROR: getCountriesSelect: " . $this->c_db->ErrorMsg() . ": SQL: $sql");
        return false;
    }

    return $countries;
}

And the problem is, in the database, pd_citizenship_country_id is never saving, while country_id saves. Why?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 相敏解调 matlab
    • ¥15 求lingo代码和思路
    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?