0

私はしばらくの間問題を見つけようとしてきましたが、何も見えません。問題を見つけるのに助けが欲しいです.

コントローラーでテーブルを作成し、それを別のページにエコーアウトしていますが、結果を見ると 2 回書き込まれています。

        $results = $this->main_model->search();

        $table_row = array();
        foreach ($results->result() as $product)
        {
          $table_row = NULL;
          $table_row[] = $product->product_id;
          $table_row[] = $product->title;
          $table_row[] = $product->description;
          $table_row[] = $product->price;
          $table_row[] = $product->stock;
          $table_row[] = $product->cat_name;
          $table_row[] = $product->subcat_name;
          $table_row[] = anchor('admin/edit/' . $product->product_id, 'edit');

          $this->table->add_row($table_row);
        }    

        $table = $this->table->generate($results);

        $data['table'] = $table;

        $this->load->view('search',$data);

結果を返す方法に問題があると思いますが、それが何であるかは完全にはわかりません。私はいくつかの方法を試しましたが、これはかなり新しいです。前もって感謝します

4

2 に答える 2

1

このコードを使用して手動で行を追加しているため、重複していると思います

foreach ($results->result() as $product)
    {
      $table_row = NULL;
      $table_row[] = $product->product_id;
      $table_row[] = $product->title;
      $table_row[] = $product->description;
      $table_row[] = $product->price;
      $table_row[] = $product->stock;
      $table_row[] = $product->cat_name;
      $table_row[] = $product->subcat_name;
      $table_row[] = anchor('admin/edit/' . $product->product_id, 'edit');

      $this->table->add_row($table_row);
    }    

アップデート

この行を変更します

$results_table = $this->table->generate($results);

これに

$results_table = $this->table->generate();
于 2013-02-28T16:38:05.350 に答える
0

$this->table->generate(); 生成されたテーブルを含む文字列を返します。行を手動で追加していない場合は、配列またはデータベース結果オブジェクトになるオプションのパラメーターを受け入れます。

しかし、あなたの場合、すでに行を追加しています

 $this->table->add_row($table_row);

そして再びあなたはそれらを

 $results_table = $this->table->generate($results);

代わりに add 行の行をコメント化します

$table_row = array();
        foreach ($results->result() as $product)
        {
          $table_row = NULL;
          $table_row[] = $product->product_id;
          $table_row[] = $product->title;
          $table_row[] = $product->description;
          $table_row[] = $product->price;
          $table_row[] = $product->stock;
          $table_row[] = $product->cat_name;
          $table_row[] = $product->subcat_name;
          $table_row[] = anchor('admin/edit/' . $product->product_id, 'edit');

//          $this->table->add_row($table_row); comment this line
        }    

        $results_table = $this->table->generate($results);
于 2013-02-28T16:41:06.473 に答える