Welcome Guest, Not a member yet? Register   Sign In
Apply the function to the string results from DB
#1

[eluser]behnampmdg3[/eluser]
Can't get the view to show the description with str_replace function applied to it! Any reasons why not?

Thanks

Model
Code:
public function post_details($id)
{
  $sql = "SELECT blog.id               AS BLOG_ID,
        blog.title            AS BLOG_TITLE,
        blog.description,
        blog.category,
        blog_categories.title AS CATEGORY_TITLE
    FROM   blog
        INNER JOIN blog_categories
          ON blog.category = blog_categories.id
    WHERE  blog.id = ?";
  $query = $this->db->query($sql, array($id));
  return $query->result();
}
Controller
Code:
$data_body=$this->blogs->post_details($id);
$data_body['description'] = str_replace("  ", "  ",  $data_body['posts'][0]->description);
this->parser->parse('blog_details', $data_body);
View
Code:
{posts}
    {description}
{/posts}
#2

[eluser]TheFuzzy0ne[/eluser]
Does it work as expected without str_replace?
#3

[eluser]behnampmdg3[/eluser]
[quote author="TheFuzzy0ne" date="1369157028"]Does it work as expected without str_replace?[/quote]Yes it works fine but I cant get it to apply the function to it Sad
#4

[eluser]TheFuzzy0ne[/eluser]
Are you wanting to apply str_replace() to every post? If you want to use str_replace() on each entry, you'll need to loop through the array, or you can do it at the database level with REPLACE(). In any case, I would suggest that you do it in your model, rather than your controller.

However, I'm not quite sure what you're trying to achieve. Are you sure that your posts contain two consectutive whitespaces?




Theme © iAndrew 2016 - Forum software by © MyBB