为什么我的选择框生成器不显示表中的所有选项?

时间:2015-12-21 12:00:52

标签: php mysql

我正在创建一个选择框生成器(称为ListGenerator),它需要从名为categories的表中获取选项名称并将它们添加到选择框中。数据库也从表单更新,允许用户输入要添加到选择框的新选项。

目前,生成器仅采用最后输入的名称并将其显示在选择框中。我相信生成器直接从表单而不是查询得到结果?下面是从表单到表的数据的INSERT代码以及应该从表中选择所有内容并将其放在选择框中的查询。

var book = Backbone.Model.extend();
var cols = Backbone.Collection.extend({
    model:book,
    url:"http://localhost/bbq/books.php"
});

var col  = new cols();
var view = Backbone.View.extend({

 el:'#listview',
 initialize:function () {
     _.bindAll(this, "render"); 
     this.model.fetch({
        success:this.render  
    });
 }, 

 render: function () {
      _.each(this.model.models, function (mode) {
          $(this.el).append( new listUsers({model:mode}).render.el );
     },this);
     return this;
 }

});

var listUsers = Backbone.View.extend({
   template: _.template($('#item').html()),
   render:function () {  
     $( this.el ).html( this.template( this.model.toJSON() ) );  
     return this;
   }
});
var vieb = new view({ model : col });

下面是ListGenerator的代码,在上面的代码中输入固定字符串到 - > setList函数时,这个工作正常:

<?php
$content = '<root><textarea id="something"></textarea><div id="someDiv" class="whatever"></div><img src="your_src" /><br /><br /></root>';

$xml = new DOMDocument('1.0');
$xml->loadXML(utf8_encode($content));
$xml->formatOutput = true; 
$temp=$xml->saveXML(NULL, LIBXML_NOEMPTYTAG);
$temp = utf8_decode($temp);

$closings = array('area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr');
foreach($closings AS $c){
    $temp = str_replace('</'.$c.'>', '', $temp);
}

var_dump($temp);

1 个答案:

答案 0 :(得分:0)

未经测试,但我认为它应该取得这样的结果吗?

$categoryresults = $pdo->query('SELECT * FROM categories');
$listitems=array();

while( $rs=$categoryresults->fetch( PDO::FETCH_OBJ ) ){
    $listitems[]=$rs->name
}
$ListGenerator->setList( $listitems );