![]() |
Selecting? - 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: Selecting? (/showthread.php?tid=48935) Pages:
1
2
|
Selecting? - El Forum - 02-02-2012 [eluser]Andeh17[/eluser] How would you select from the database if a users is_admin status is equal to 1? I currently have these... controller: Code: function is_admin() view: Code: if($this->is_admin()) Thanks in advance. Selecting? - El Forum - 02-02-2012 [eluser]meigwilym[/eluser] I think that's ok, but a more concise approach might be Code: function is_admin() Anyone else any thoughts? (in case I'm wrong) Cheers, Mei Selecting? - El Forum - 02-02-2012 [eluser]Andeh17[/eluser] [quote author="meigwilym" date="1328195989"]I think that's ok, but a more concise approach might be Code: function is_admin() Anyone else any thoughts? (in case I'm wrong) Cheers, Mei[/quote] Sorry I forgot to include the error, thanks for that but it still isn't working. Fatal error: Call to undefined method CI_Loader::is_admin() And it is throwing it on this line... if($this->is_admin()) Am I supposed to load the controller or something to call the function? I'm so confused right now. Selecting? - El Forum - 02-02-2012 [eluser]PhilTem[/eluser] I prefer Code: function is_admin($username) because it's much shorter (if you compress code) and you actually don't run a real select query but more a 'SELECT COUNT(*) FROM' query. Which is a little fail safer for sql-injections since it only returns a number and no full rows. But both queries are right. I like mine just a little more since it only counts matches and doesn't select them ![]() Refer to CI user's guide -> database class -> active record. Selecting? - El Forum - 02-02-2012 [eluser]Andeh17[/eluser] [quote author="PhilTem" date="1328196906"]I prefer Code: function is_admin($username) because it's much shorter (if you compress code) and you actually don't run a real select query but more a 'SELECT COUNT(*) FROM' query. Which is a little fail safer for sql-injections since it only returns a number and no full rows. But both queries are right. I like mine just a little more since it only counts matches and doesn't select them ![]() Refer to CI user's guide -> database class -> active record.[/quote] But that still doesn't fix why i'm receiving.. Fatal error: Call to undefined method CI_Loader::is_admin() in /Applications/XAMPP/xamppfiles/htdocs/codeigniter/application/views/logged_in_area.php on line 15 What is on that line: if($this->is_admin($this->session->userdata('username'))) Cheers anyway. Selecting? - El Forum - 02-02-2012 [eluser]InsiteFX[/eluser] And what does - Call to undefined method mean? This is basic PHP! Selecting? - El Forum - 02-02-2012 [eluser]Bhashkar Yadav[/eluser] this error is related to code into view file : Code: if($this->is_admin()) Selecting? - El Forum - 02-02-2012 [eluser]Andeh17[/eluser] [quote author="InsiteFX" date="1328198090"]And what does - Call to undefined method mean? This is basic PHP! [/quote] Yes it's basic PHP, i'm new to CodeIgniter and frameworks so cut me some slack. And I just can't see where the errors coming from, not my fault. Selecting? - El Forum - 02-02-2012 [eluser]CroNiX[/eluser] What is the column name in your table that tells if they are admin or not? Selecting? - El Forum - 02-02-2012 [eluser]Andeh17[/eluser] [quote author="CroNiX" date="1328203609"]What is the column name in your table that tells if they are admin or not?[/quote] @CroNiX it's is_admin |