Welcome Guest, Not a member yet? Register   Sign In
blog from tutorial
#1

[eluser]paulon[/eluser]
hi guys im new in CI

i follow the instruction from tutorial regarding how to craete a blog, everything working fine..
but now i want to change the comment heading to the blog title and body how is it im getting some error in db.
i change the actual function of comments so i can make the heading equal to comments title and body. here the code

Quote: function comments(){
$this->db->select('title,body');
$this->db->where('id',$this->uri->segment(3));
$query = $this->db->get('entries');

if($query->result() as $row){
$data['title'] = $row->title;
$data['heading'] = $row->body;
}

$this->db->where('entry_id',$this->uri->segment(3));
$data['query'] = $this->db->get('comments');
$this->load->view('comment_view',$data);

}

Im getting the error from if($query->result() as $row), seems like the error occur when im passing the $query->result to $row....

any idea? =(
#2

[eluser]summery[/eluser]
Congrats on learning CI, glad you got the blog working so far!

I think the problem is that "if" and "as" are not usually used together. Instead, just use an if statement. Since you're querying on an id, you'll only get one row back:

Code:
if ($query->num_rows() > 0)
{
   $row = $query->row();
   $data[‘title’] = $row->title;
   $data[‘heading’] = $row->body;
}

Also, I think you might get some unexpected results with your title and heading. The title is an html title that appears at the top of your browser window; the heading is an h1 heading that appears at the top of the page. You probably don't want your entire blog post in huge, bold black type before your comment form. Try:

Code:
$data[‘title’] = $row->title . " Comments | My Site";
$data[‘heading’] = $row->title;

Good luck, let me know if it works/if you solved it some other way!
#3

[eluser]paulon[/eluser]
yes your right “if“ and “as” are not usually used together.

thanks for the reply it works fine now., and regard the title and heading i usualy change their tags the $title goes to header tag and $heading to paragraph tag




Theme © iAndrew 2016 - Forum software by © MyBB