Welcome Guest, Not a member yet? Register   Sign In
Transfering db multi result data from controller -> view
#1

[eluser]Falney[/eluser]
I wish to use multi result data from a db query in a jump too menu. This is something I have done multiple times easily before starting to use CodeIgniter (This is my first project) and for the life of my I cant seem to figure a way to transport the results from the controler with the query in it to the view that is outputting the data.

Is there an easy way to do this? Best Ive done so far is the first or last result from the query.

Id rather not add unneccessary complexity too my view files, but if I have to I will do the queries there.

edit:

Best thought so far was to use a multidimentional array but I didnt have any luck with that. Not sure why
#2

[eluser]vickel[/eluser]
Hopefully this helps:
Generating Query Results @ http://ellislab.com/codeigniter/user-gui...sults.html

There are several ways to generate query results:
result()

This function returns the query result as an array of objects, or an empty array on failure. Typically you'll use this in a foreach loop, like this:
$query = $this->db->query("YOUR QUERY");

foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->body;
}

The above function is an alias of result_object().

If you run queries that might not produce a result, you are encouraged to test the result first:
$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->body;
}
}
#3

[eluser]Falney[/eluser]
I dont think getting the data from the db is the problem. Im having trouble outputting it.

My model;

function view_server()
{
$uuid = $this->session->userdata('uuid');

$this->db->where('UUID', $uuid);
$query = $this->db->get('TBL_DV_SERVERS');
return $query->result();
}

my controller;

function index()
{
$this->load->model('digivend');

$data['query'] = $this->digivend->view_server();

$this->load->view('headder');
$this->load->view('dv_server_view', $data);
$this->load->view('footer');
}

Im having trouble extracting the data on the view.

Up until starting with CI (yesterday) I would have done the query and then I would have populated the jumpto menu in the loop. Something like this

while ($server_row = mysql_fetch_array($server_result))
{
echo'<option value="' . $server_row['SERVER_ID'] . '">'
. $server_row['SERVER_NAME'] . '</option>';
}

The Database schem
SERVER_NAME | SERVER_ID | UUID | URL | TYPE

What Im unsure of is what I need to do to populate the jump menu. Now I feel dumb Smile

Im sorry I didnt include this data in my initial post.

PS Database is pre loaded Smile
#4

[eluser]vickel[/eluser]
use in your view something like:

Code:
&lt;?php foreach($query as $row):?&gt;
&lt;?=$row->UUID?&gt;
&lt;?php endforeach;?&gt;
#5

[eluser]Falney[/eluser]
That worked fantastically. Thank you very much
#6

[eluser]vickel[/eluser]
happy holidays Smile come visit me @ http://www.surfericeira.com




Theme © iAndrew 2016 - Forum software by © MyBB