Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
More Jobs
Recent
Human Date Method
Company hCard
Markdown-like editor
Generating a string of random characters
Cache SQL Server Views
TableAdapter and CommandTimeout
Custom blowfish IRC implementation
Template Method
Merge generic lists
Tracking error in numbers
Popular
TableAdapter and CommandTimeout
Merge generic lists
Template Method
Cache SQL Server Views
Generating a string of random characters
Markdown-like editor
Company hCard
Human Date Method
Custom blowfish IRC implementation
kill nginx master proces
Pastable version of
get username from database
<div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15</pre> <pre class="sunburst"><?php <span style="color:#99CF50;">function</span> <span style="color:#89BDFF;">username</span>(<span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>user_id</span> <span style="color:#E28964;">=</span> <span style="color:#3387CC;">null</span>) { <span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>user_id</span> <span style="color:#E28964;">=</span> (<span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>user_id</span> <span style="color:#E28964;">!</span><span style="color:#E28964;">=</span> <span style="color:#3387CC;">null</span>) ? <span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>user_id</span> : current_user()<span style="color:#E28964;">;</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">//</span> if inserted ID to function, else return logged user ID</span> <span style="color:#E28964;">if</span> ( <span style="color:#E28964;">!</span><span style="color:#9B859D;">User</span><span style="color:#E28964;">::</span>get_user_details(<span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>user_id</span>) ) <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">//</span> if user does not exists</span> <span style="color:#E28964;">return</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>id</span><span style="color:#E28964;">;</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">//</span> return only ID</span> <span style="color:#E28964;">else</span> { <span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>inner</span> <span style="color:#E28964;">=</span> <span style="color:#9B859D;">User</span><span style="color:#E28964;">::</span>get_user_details(<span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>user_id</span>)<span style="color:#E28964;">;</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">//</span> if user exist</span> <span style="color:#E28964;">return</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">$</span>inner</span>[<span style="color:#65B042;"><span style="color:#65B042;">'</span>username<span style="color:#65B042;">'</span></span>]<span style="color:#E28964;">;</span> <span style="color:#AEAEAE;font-style:italic;"><span style="color:#AEAEAE;font-style:italic;">//</span> return ID username</span> } } ?> </pre> </div> </div> <a href="http://refactormycode.com/codes/287-get-username-from-database" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://refactormycode.com/images/small_logo.gif" style="border:0" /></a>