CodeIgniter Forums
Simple model question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Simple model question (/showthread.php?tid=31122)



Simple model question - El Forum - 06-07-2010

[eluser]DADE[/eluser]
Hey there,
I have a problem with model. I'm new in CI, so can you please answer more detailed. OK so:

I need drag from MySQL table random rows. And I want to create Model like:
Code:
$this->myModel->drag_user(user id here);
But I don't know how I can use this ID...

I need something like:

1. I load my model with ID 3.
Code:
$this->myModel->drag_user(3);

2. And now he loads user with ID 3 for me.
Code:
function drag_user(3) {
        $sql = "SELECT * FROM users WHERE id = 3";
        $q = $this->db->query($sql);
        return $q;
     }

How I can realize this? Smile
P.S: Sorry for bad english.


Simple model question - El Forum - 06-07-2010

[eluser]MaartenDeGroote[/eluser]
So what exactly is your question?


Simple model question - El Forum - 06-07-2010

[eluser]DADE[/eluser]
How I can make model work when I write
Code:
...->drag_user(3)
and it'll take user with ID 3 from database?


Simple model question - El Forum - 06-07-2010

[eluser]MaartenDeGroote[/eluser]
Do you mean this?

Code:
function drag_user($id)
{
$sql = "SELECT * FROM users WHERE id = ?";
$q = $this->db->query($sql, $id)->row();
return $q;
}



Simple model question - El Forum - 06-07-2010

[eluser]DADE[/eluser]
Yeap, thank you.