CodeIgniter Forums
Shorthand - 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: Shorthand (/showthread.php?tid=11065)



Shorthand - El Forum - 08-25-2008

[eluser]RESPECT[/eluser]
This is just a general PHP question...Im wondering if this would work:

Code:
$query = $this->db->get_where('portfolio', array('id' => $id), 1)  = (!$query) ? return $query->row() : return false;

Or would I have to do it this way?

Code:
$query = (!is_null($this->db->get_where('portfolio', array('id' => $id), 1))) ? return $query->row() : return false;

Thanks in advance!


Shorthand - El Forum - 08-25-2008

[eluser]Colin Williams[/eluser]
What's the point?

If they work, they work, but I would advise against either.


Shorthand - El Forum - 08-25-2008

[eluser]RESPECT[/eluser]
well just wondering which one does...im on a really slow pc for a while and my host is down. So im just curious if anyone know if it would work...runtime wise


Shorthand - El Forum - 08-25-2008

[eluser]xwero[/eluser]
I think both examples don't work. If you would want to do something like that i think this is the way to go
Code:
return ($query = $this->db->get_where('portfolio', array('id' => $id), 1))? $query->row() : false;



Shorthand - El Forum - 08-25-2008

[eluser]wiredesignz[/eluser]
I'm all for shortened code too, and I can understand xwero's example.

Which ever coding style you choose, just make sure it will make sense to you when you read it again in six months time.