Welcome Guest, Not a member yet? Register   Sign In
CodeExtinguisher's Website Code
#12

[eluser]Isern Palaus[/eluser]
Ouch... first problem understanding one of the models:

I'm in http://jtaby.com:82/svn/codex_site/syste...gins_m.php:

Code:
function  getPlugins ($num=-1,$offset=-1){
    $sql = "SELECT * from plugins order by created_at desc";
    if($num != -1)
        $sql .= " limit ";
    if($num != -1 AND $offset != -1)
        $sql .= "$offset,";
    if($num != -1)
        $sql .= "$num";
    
    $query = $this->db->query($sql);
    return $query->result_array();
}

I don't understand why you set -1 value. I suppose this value is set if no value is passed when you call the function on a controller.

It's called on controller plugins.php

Code:
if($num === "all"){
    $data['plugins'] = $this->plugins_m->getPlugins($config['per_page']);
}
else{
    if(!isset($num) OR !is_numeric($num)) $num = 0;
    $data['plugins'] = $this->plugins_m->getPlugins($config['per_page'],$num);
    $data['replies'] = $this->plugins_m->getThreads($num);
}

When you the $num (segment 3 on the URI) is equal at all you call $this->plugins_m->getPlugins($config['per_page']); the getPlugins() will create a SQL like this:

Code:
SELECT * from plugins order by created_at desc limit 10
(Supposing that $config['per_page] = 10)

What more, if you call $this->plugins_m->getPlugins($config['per_page'],$num) will create a SQL like this:

Code:
SELECT * from plugins order by created_at desc limit 10,10

It is?

Thanks in advance and thanks for sharing!

See you,
-- Isern Palaus


Messages In This Thread
CodeExtinguisher's Website Code - by El Forum - 12-15-2007, 01:18 PM
CodeExtinguisher's Website Code - by El Forum - 12-15-2007, 02:45 PM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 01:44 AM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 02:04 AM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 02:20 AM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 02:26 AM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 02:34 AM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 12:28 PM
CodeExtinguisher's Website Code - by El Forum - 12-16-2007, 10:07 PM
CodeExtinguisher's Website Code - by El Forum - 12-17-2007, 02:41 AM
CodeExtinguisher's Website Code - by El Forum - 12-22-2007, 03:31 PM
CodeExtinguisher's Website Code - by El Forum - 12-22-2007, 03:54 PM
CodeExtinguisher's Website Code - by El Forum - 12-23-2007, 05:23 AM
CodeExtinguisher's Website Code - by El Forum - 12-23-2007, 05:29 AM
CodeExtinguisher's Website Code - by El Forum - 12-23-2007, 10:18 AM
CodeExtinguisher's Website Code - by El Forum - 12-28-2007, 11:13 AM
CodeExtinguisher's Website Code - by El Forum - 01-28-2008, 05:20 AM
CodeExtinguisher's Website Code - by El Forum - 01-28-2008, 08:03 AM
CodeExtinguisher's Website Code - by El Forum - 02-07-2008, 09:17 AM
CodeExtinguisher's Website Code - by El Forum - 06-30-2009, 12:59 PM
CodeExtinguisher's Website Code - by El Forum - 06-30-2009, 01:16 PM
CodeExtinguisher's Website Code - by El Forum - 06-30-2009, 04:35 PM
CodeExtinguisher's Website Code - by El Forum - 11-30-2009, 08:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB