CodeIgniter Forums
Shorter way to do this ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Shorter way to do this ? (/showthread.php?tid=31958)



Shorter way to do this ? - El Forum - 07-08-2010

[eluser]chefnelone[/eluser]
Hello,

I just want to know if is there a way write this in one single line:

Code:
$products = $this->db->get('products');
return $products->result();

thanks


Shorter way to do this ? - El Forum - 07-08-2010

[eluser]mddd[/eluser]
Sure.
Code:
return $this->db->get('products')->result();



Shorter way to do this ? - El Forum - 07-08-2010

[eluser]chefnelone[/eluser]
[quote author="mddd" date="1278599758"]Sure.
Code:
return $this->db->get('products')->result();
[/quote]

thanks mddd.


Shorter way to do this ? - El Forum - 07-08-2010

[eluser]WanWizard[/eluser]
Note: PHP5 only.


Shorter way to do this ? - El Forum - 07-08-2010

[eluser]wiredesignz[/eluser]
[quote author="WanWizard" date="1278607836"]Note: PHP5 only.[/quote]

So are you saying that PHP6 does not have this feature then?


Shorter way to do this ? - El Forum - 07-08-2010

[eluser]Twisted1919[/eluser]
And if no result is returned ?


Shorter way to do this ? - El Forum - 07-08-2010

[eluser]WanWizard[/eluser]
[quote author="wiredesignz" date="1278608433"][quote author="WanWizard" date="1278607836"]Note: PHP5 only.[/quote]
So are you saying that PHP6 does not have this feature then?[/quote]
:lol: No, I mean that CI still claims PHP4 compatibility, and that you'll lose that if you use this feature. Depending on the TS' environment that might be relevant.


Shorter way to do this ? - El Forum - 07-08-2010

[eluser]Jelmer[/eluser]
[quote author="Twisted1919" date="1278617726"]And if no result is returned ?[/quote]
Code:
$products = $this->db->get('products')->result();
if (empty($products))
{
    // do something for empty condition
}
else
{
    // show the products...
}