Welcome Guest, Not a member yet? Register   Sign In
Getting data from table in one line?
#11

[eluser]mitnick[/eluser]
"helpers" Wink.
#12

[eluser]Flemming[/eluser]
try removing everything from the 'helper'. Load it in the controller but don't try accessing it from the view.

still a blank page?
#13

[eluser]mitnick[/eluser]
If i remove the content from the helper everything loads up just fine.
#14

[eluser]Flemming[/eluser]
great! can you post your entire helper file please? (inside [ code ] tags please)
#15

[eluser]mitnick[/eluser]
I created a new helper file called snippet_helper.php

Inside it i have the following.

Code:
<?php

function get_body($id)
{
  // here you need to use the CI super object like so:
  $CI = &get;_instance();

  // now you can access the database via $CI instead of $this, eg.
  $CI->db->select('body')->from('snippets')->where('ID', $id);
  $query = $CI->db->get();
  $result = $query->row();
  $body = $result->body;
  return $body
}

And added

Code:
$this->load->helper('snippet');

to my admin.php controller.

Can you see anything wrong with this?. I have a table called "snippets" in the DB with the structure of ID,Title,Body.
#16

[eluser]Flemming[/eluser]
sorry - that was my fault ... i mistyped this line originally, then edited it, obviously after you'd already copied it! ...
Quote:// here you need to use the CI super object like so:
$CI = &get;_instance();

should be:

Code:
//here you need to use the CI super object like so:
$CI = &get;_instance();

grrrr ... almost did it again!

Code:
$CI = & get _ instance();
is the correct version! (without the spaces)
#17

[eluser]Flemming[/eluser]
and just to clarify ...

Code:
$CI = & get_instance();

is correct!
#18

[eluser]mitnick[/eluser]
Tried

Code:
<?php

function get_body($id)
{
  // here you need to use the CI super object like so:
  $CI = & get_instance();

  // now you can access the database via $CI instead of $this, eg.
  $CI->db->select('body')->from('snippets')->where('ID', $id);
  $query = $CI->db->get();
  $result = $query->row();
  $body = $result->body;
  return $body
}

and

Code:
<?php

function get_body($id)
{
  // here you need to use the CI super object like so:
  $CI = &get;_instance();

  // now you can access the database via $CI instead of $this, eg.
  $CI->db->select('body')->from('snippets')->where('ID', $id);
  $query = $CI->db->get();
  $result = $query->row();
  $body = $result->body;
  return $body
}

Without luck.. P.s.: It seems like the "code view" here on the forums adds a ";" after "get" automatically but i added it without the ";" and still the same issue?. Hmm, this is weird..
#19

[eluser]Flemming[/eluser]
Quote:I have a table called “snippets” in the DB with the structure of ID,Title,Body.

make sure your field names match your PHP ... if you want to use $result->body in your PHP then you need to rename the field in the DB ... or use $result->Body in your helper!

you will get this working!
#20

[eluser]mitnick[/eluser]
Hey,

I figured it out. The first issue was the _instance. Also there was a closing ";" missing at the end of the last line.




Theme © iAndrew 2016 - Forum software by © MyBB