Page 1 of 1

Why can't I do something like....

Posted: Thu Oct 08, 2009 9:28 am
by BDKR

Code: Select all

 
$config['total_rows'] =($this->db->get_where('crawled', array('base_url' => $domain)))->num_rows();
 
Codeigniter people will recognize some of this stuff. :twisted:

Anyway, what I want is to query the db (which is what $this->db->get_where() is doing) then get the row count using a method of the returned object.

Perhaps I've been around Ruby people too long. That line of code up there certainly ain't Pythonic. LOL

Re: Why can't I do something like....

Posted: Thu Oct 08, 2009 10:45 am
by McInfo
The extra parentheses should not be used in that statement.

Does the get_where() method return an object that has a num_rows() method?

This works.

Code: Select all

<?php
class Main {
    var $db;
    function  __construct() {
        $this->db = new Db();
        $this->db->get_where()->num_rows();
    }
}
class Db {
    function get_where () {
        return $this; // Returns the current Db object
    }
    function num_rows () {
        echo 'Hello, World.';
    }
}
new Main();
Edit: This post was recovered from search engine cache.

Re: Why can't I do something like....

Posted: Thu Oct 08, 2009 7:20 pm
by BDKR
McInfo wrote: The extra parentheses should not be used in that statement.
OK. I tried it without the parentheses and it worked. Imagine that! It made logical sense that I would need them you know? As an example of my thinking.

Code: Select all

 
<?php
$result=(99+45)*2;
print_r($result);   echo "\n";
?>
 
So like for "$result" (and I know you know this), I wanted the result of the sum operation before multiplying by 2. It was my assumption (and I think a logical one) that I would need to write the expression in the same way. Remove the parentheses and the result is different of course.

But oh well. I was just having one of those "wouldn't it be nice if" moments so I decided to post it. I'm glad I did.

Thanx mang! :D