CodeIgniter Forums
Querying result in view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Querying result in view (/thread-40928.html)



Querying result in view - El Forum - 04-22-2011

[eluser]jacobson[/eluser]
Hello, I have a problem.
I have php code

function display() {
global $database;
$q = "SELECT value1, value2, value3 FROM " . TBL_1 . " LIMIT 0,10";
$result = $database->query($q);
$num_rows = mysql_numrows($result);
if (!$result || ($num_rows < 0)) {
echo "error";
return;
}
if ($num_rows == 0) {
return;
}
for ($i = 0; $i < $num_rows; $i++) {
$val1 = mysql_result($result, $i, "value1");
$val2 = mysql_result($result, $i, "value2");
$val3 = mysql_result($result, $i, "value3");
echo "<div id=\"content_main_entry\"><a >
<span class=\"content_main_entry_value\">" . $val2 . "</span>
<span class=\"content_main_entry_value\">" . $val3 . "</span>
<div id=\"content_main_entry_enroll\"></div>";
}
}

And I want to create the same using the codeigniter code. I've tried but I dunno how to send all the data into the view. I tries in controller setting variable
$this->db->select('value1,value2,value3');
$data['records'] = $this->db->get(TBL_1);
And now I send this variable to my view
$this->load->view('myview',$data);

And I'm stuck... Have no idea how to access all the data (in the way I showed in my php code)

I would be thankful for help


Querying result in view - El Forum - 04-22-2011

[eluser]Alias M2K[/eluser]
Man, you have to get the data in the controller. Then load them into the view. In the view, use foreach to sort out and manipulate the data. Ok?