Jeff Davidson
Jeff Davidson

Reputation: 1929

Table Creation From HTML Table Class

Trying to figure out how I can do this properly.

The print_r looks like this:

Array ( [0] => stdClass Object ( [quote] => "Now that's wonderful!" ) ) 

Table Creation:

$tmpl = array ( 'table_open'  => '<table class="table" id="quotes-table">' );
$this->table->set_template($tmpl); 
print_r($quotes);
$data = array(
    array(form_checkbox('quotes'), 'Quote'),
    array(form_checkbox('quotes'), 'Testing Quote Here'),
    array(form_checkbox('quotes'), $quotes['quote'])
);
echo $this->table->generate($data); 
?>

UPDATE:

Problem though when I add more t than 1 row it only returns that one row. So basically I want an object that can be returned from the query so that in the view I can just simply do $quote->quote. That way it will show all quotes for the user.

<?php
$tmpl = array ( 'table_open'  => '<table class="table" id="quotes-table">' );
$this->table->set_template($tmpl);
$checkbox_data = array(
    'name'        => 'quote',
    'id'          => $quotes->id
); 
$data = array(
    array(form_checkbox($checkbox_data), 'Quote'),
    array(form_checkbox($checkbox_data), $quotes->quote)
);
echo $this->table->generate($data); 

Upvotes: 0

Views: 302

Answers (2)

Robert
Robert

Reputation: 1907

In answer to your update, try something like this:

<?php

// Your query
$results = $this->db->get('quotes')->result();

$this->table->set_heading('Name', 'Quote');

foreach ($results as $result)
{
   // The name is the user's name, not sure if that's what you were going for.
   $this->table->add_row($result->name, $result->quote);
}

echo $this->table->generate();

It's all here: http://codeigniter.com/user_guide/libraries/table.html

Upvotes: 1

Robert
Robert

Reputation: 1907

You did not say what the problem is, but if you're not seeing your quote, try changing this:

array(form_checkbox('quotes'), $quotes['quote'])

Into this:

array(form_checkbox('quotes'), $quotes[0]->quote)

Edit: Some additional clarification.

  Array ( [0] => stdClass Object ( [quote] => "Now that's wonderful!" ) ) 

You've got an array of 1 and that's an object. For arrays you use $array['key'] for objects $object->key. If you can't change it in the controller you could do something like this

$quotes = $quotes[0];
$quotes->quote;

Upvotes: 2

Related Questions