dqvtm82066 2016-05-24 05:30 采纳率: 0%
浏览 28
已采纳

组合框中的PHP不需要的空行

I'm filling to combobox from database. Everything is ok so far, however when i check to html result, there are empty option tag foreach row in combobox. There aren't null row in table. I don't achieve a solution, the problem occurs only on this get_flight_locations function.

Result

    <select class="form-control" name="flightfrom">
        <option>Choose please</option>
        <option value="1">Baku-GYD</option>
        <option></option>
        <option value="2">Berlin-TXL</option>
        <option></option>                       
    </select>

index.php

<?php
    $lst_to = Database::getInstance()->get_flight_locations();
?>

<select class="form-control" name="flightfrom">
    <option><?php echo $lang[$clang]["lblChoose"] ?></option>
    <?php
        while($row = mysqli_fetch_array($lst_to)) {
            printf(
                "<option value=\"%s\">%s-%s<option>", 
                $row["city_id"], 
                $row["city_name"], 
                $row["airport_code"]
            );
        }
    ?>
</select>

Database class

<?php

    class Database extends mysqli {
        private $db   = DB_NAME;
        private $user = DB_USER;
        private $pass = DB_PASS;    
        private $host = DB_HOST;

        private static $instance = null;

        public static function getInstance() {
            if (!self::$instance instanceof self) {
                self::$instance = new self;
            }
            return self::$instance;
        }

        private function __construct() {
            parent::__construct($this->host, $this->user, $this->pass, $this->db);
            if (mysqli_connect_error()) {
                exit('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
            }
            parent::set_charset('utf-8');
        }

        public function __clone() {
            trigger_error('Clone is not allowed', E_USER_ERROR);
        }

        public function __wakeup() {
            trigger_error('Deserializing is not allowed', E_USER_ERROR);
        }

        public function get_flight_locations() {
            return $this->query("select * from v_flight_location");
        }
    } 
?>
  • 写回答

1条回答 默认 最新

  • doucong1853 2016-05-24 05:38
    关注

    You forgot / symbol in option close tag. So instead of closing <option> tag, it opens another one.

    Here's a fix:

               printf(
                    "<option value=\"%s\">%s-%s</option>", 
                    $row["city_id"], 
                    $row["city_name"], 
                    $row["airport_code"]
                );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败