duanmeng2842 2015-05-28 02:26
浏览 96

为什么在我的下拉列表中显示我的第一个选项?

I don't know what is the problem.

I have this part of my php:

public function fillObject(){

try {

    $servername = "localhost";
    $username = "root";
    $password = "123asd";
     $conn = new PDO("mysql:host=$servername;dbname=bd_actividades", $username, $password);
     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $stmt = $conn->prepare("SELECT pro_nombre FROM act_proyecto");
     $stmt->execute();
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $result = $stmt->fetchAll();


    foreach ($result as $row) {
    $aObjects=array();
    $oTransfer = new TransferProyeCtr();

    $oTransfer->setNombre($row['pro_nombre']);

    $oTransfer->setState(1);
    $aObjects[]=$oTransfer;
    return $aObjects;
} }catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
} }

this send the results : $oTransfer->setNombre($row['pro_nombre']);

And in my dropdown show this:

enter image description here

But I need this :

enter image description here

What is the problem? Here is my module where I print:

Ajax:

llenarComboProyectos: function(iSecciones){

    var self = this;

    self.ajaxCall('http://localhost:8080/PROJECTS/dailytasks/api/sistemaTareas/v1/'+"proyectos","GET", null).then(function(data) {
        console.info("data",data);
        if(self.checkError(data[0].state)){
            self.llenarCombos(iSecciones,data);
        }else{
            alert("error service");
        }
    });
},

Where I print:

llenarCombos: function(secciones,data){

        var self = this;    
        console.info(data);
        for (var i = 0; i < data.length; i++){
            var cProyectos = "<option>"+data[i].nombre_proyecto+"</option>"; 
            for(var iCont=0;secciones>=iCont; iCont++){
                $("#select_proyecto_"+iCont+"_id").append(cProyectos);
                $("#select_proyecto_"+iCont+"_id").selectpicker('refresh');  
            }   
        }
},  

here I get pro_nombre: var cProyectos = "<option>"+data[i].nombre_proyecto+"</option>";

  • 写回答

1条回答 默认 最新

  • doushi7819 2015-08-11 11:33
    关注

    Please remove

    $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    

    from your first script. I think this will solve your problem.

    1. http://php.net/manual/en/pdostatement.fetch.php

    2. http://php.net/manual/en/pdostatement.fetchall.php

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c