Welcome Guest, Not a member yet? Register   Sign In
Why is this labeled undefined?
#1

[eluser]DaTran[/eluser]
To me it doesn't look like $id is undefined?

print_r() comes out as:

Code:
Array
(
    [id] => 10
    [min_bid] => 23456789
    [item_id] => 12
    [list] => Array
        (
            [0] => stdClass Object
                (
                    [name] => Black Leather Long Bow
                    [id] => 13
                )

            [1] => stdClass Object
                (
                    [name] => Claymore
                    [id] => 4
                )

            [2] => stdClass Object
                (
                    [name] => Pink Glad
                    [id] => 12
                )

        )

)

and my view page
Code:
<?php echo form_open('auction/edit/'.$id); ?>
    <p>
        <label for="items">Item:</label>
        <select name="items">
            <option>Select an Item</option>
            &lt;?php foreach($list as $row): ?&gt;
            <option value="&lt;?php echo $row->id ?&gt;">&lt;?php echo $row->name; ?&gt;</option>
            &lt;?php endforeach; ?&gt;
        </select>
    </p>
&lt;?php echo form_close(); ?&gt;
#2

[eluser]theprodigy[/eluser]
can I see the code from the controller that populates what you are passing into the print_r? If you are pulling from a model, I would like to see that code as well please.
#3

[eluser]DaTran[/eluser]
The controller:
Code:
elseif($data = $this->model_auction->retreave($this->uri->segment(3)))
        {
            if($query = $this->model_auction->list_items())
            {
                $data['list'] = $query;
            }
            print_r($data);
            
            $this->load->view('auction_edit', $query);
        }

The model:
Code:
function retreave($id = NUll)
    {
        if($id)
        {
            $this->db->where('id', $id);
            $query = $this->db->get('auction');

            foreach($query->result() as $row)
            {                
                // Get item name from database
                $this->db->where('id', $row->items_id);
                $item_query = $this->db->get('items');

                $item = $item_query->row_array();
            
                // Normal array
                $new_array = array(
                    'id' => $row->id,
                    'min_bid' => $row->min_bid,
                    'item_id' => $item['id']
                );

            }
            return $new_array;
        }
        else
        {
            $query = $this->db->get('auction');

            $new_array = array(); // Make array

            foreach($query->result() as $row)
            {                
                // Get item name from database
                $this->db->where('id', $row->items_id);
                $item_query = $this->db->get('items');

                $item = $item_query->row_array();

                // Add a stdClass object to the final array.
                $new_array[] = (object) array( // Adds new object array on to the array created foreach $new_array[]
                    'id' => $row->id,
                    'min_bid' => $row->min_bid,
                    'item_name' => $item['name']
                );

            }
            return $new_array; // return multi-demi array
        }
    }
#4

[eluser]DaTran[/eluser]
Found the problem I didn't rename the $query to $data before passing into view. Thanks




Theme © iAndrew 2016 - Forum software by © MyBB