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

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

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

Post 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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
Last edited by McInfo on Thu Jun 17, 2010 12:36 pm, edited 1 time in total.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

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

Post 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
Post Reply