Welcome Guest, Not a member yet? Register   Sign In
Confused After Video Tutorial
#1

[eluser]lenwood[/eluser]
Hi All,
I'm in the process of building an app with CI. I'm rusty so as a starting point I've built a basic site with a couple of static pages, and I've added the blog per the video tutorial.

When I reached the last stages of the tutorial, where Derek uses an if statement to determine whether there have been any comments yet, that produces a fatal error for me, "Call to a member function num_rows() on a non-object in...". I did a few web searches, tried a couple of different things that I found in the forums, and nothing worked.

Just to see what would happen, I pulled the if statement out altogether (and its closing endif). Now the site works exactly the way its supposed to. If a post has no comments, nothing is displayed above the comment fields.

Before I do more research and try to fin the fatal error, is there a good reason to have that present if the app works without it?

Thanks,
Chris
#2

[eluser]skunkbad[/eluser]
[quote author="lenwood" date="1270373678"]Hi All,
I'm in the process of building an app with CI. I'm rusty so as a starting point I've built a basic site with a couple of static pages, and I've added the blog per the video tutorial.

When I reached the last stages of the tutorial, where Derek uses an if statement to determine whether there have been any comments yet, that produces a fatal error for me, "Call to a member function num_rows() on a non-object in...". I did a few web searches, tried a couple of different things that I found in the forums, and nothing worked.

Just to see what would happen, I pulled the if statement out altogether (and its closing endif). Now the site works exactly the way its supposed to. If a post has no comments, nothing is displayed above the comment fields.

Before I do more research and try to fin the fatal error, is there a good reason to have that present if the app works without it?

Thanks,
Chris[/quote]

If there are no rows in a result, and you try to count them (remember they don't exist), then you get this error.
#3

[eluser]lenwood[/eluser]
[quote author="skunkbad" date="1270414646"]If there are no rows in a result, and you try to count them (remember they don't exist), then you get this error.[/quote]

Thanks for your reply skunkbad. So then, is it fine to leave this out altogether? Or would it be better to find a way to make this work?
#4

[eluser]skunkbad[/eluser]
I think if you leave it out, you probably won't see your comments. The proper usage would be to test if there is a result set before trying to count it. I'll try to post an example, but I can barely type on the computer I'm on...

EDIT

Here's a little code snippet I took out of one of my projects:

Code:
if($query->num_rows() > 0)
{
    return $query->result();
}

This makes sure that there is a result set to count while attempting to count it.




Theme © iAndrew 2016 - Forum software by © MyBB