September 7th, 2008 by
Daniel Costalis
(Who am I?)
Did you know there are actually 3 different ways to use the if…else…elseif control in PHP? They each have their uses, and hopefully I can help decode them a little bit for those who aren’t familiar with them. Here is your standard if statement:
if ($islocal) {
$user = "localhost";
} else {
$user = $logged_in_user;
}
if ($isadmin) {
$ip = "192.168.0.1";
} else {
$ip = "localhost";
}
Now, there is nothing wrong with that, but if you’re looking for something a bit cleaner, you could try it this way:
$user = ($islocal) ? "localhost" : $logged_in_user;
$ip = ($isadmin) ? "192.168.0.1" : "localhost";
Less code. Less mess. Less parsing time. Very nice. Now, what about dynamically generating html pages? I’ll use a short example of the standard way, but in practice they get quite a bit more complicated and tough to read. Here’s an example of a form the standard way:
<?php
if ($isloggedin) {
echo "<form name = 'myform' action = 'submit.php' method = 'post'>";
echo "<input name = 'firstname' value = '{$user['firstname']}'
type = 'text' />";
echo "<input name = 'lastname' value = '{$user['lastname']}'
type = 'text' />";
echo "</form>";
} else {
echo "<div class = 'errormessage'>You are not logged in.</div>";
echo "<div class = 'infotext'><p>Please <a href = 'login.php'>login
</a> or <a href = 'register.php'>register</a> before attempting
to edit your profile</p></div>";
}
?>
Now like I said, this one isn’t so bad. but imagine if you needed to display much more website content, and had to do it that way. Also, this has the caveat of being very unfriendly with any sort of visual editor like Dreamweaver. Here’s a better way:
<?php if ($isloggedin) : ?>
<form name = 'myform' action = 'submit.php' method = 'post'>
<input name = 'firstname' value = '<?php echo $user['firstname'] ?>'
type = 'text' />
<input name = 'lastname' value = '<?php echo $user['lastname']} ?>'
type = 'text' />
</form>
<?php else: ?>
<div class = 'errormessage'>You are not logged in.</div>
<div class = 'infotext'><p>Please <a href = 'login.php'>login</a> or
<a href = 'register.php'>register</a> before attempting to edit your
profile</p></div>
<?php endif; ?>
Now, this doesn’t save a whole lot of code space, but it does make everything a bit more readable. It also allows you to see exactly what you’re working with in something like dreamweaver, and copy and paste large amounts of code without having to scroll down line by line and copy/paste/copy/paste…
Hopefully these will help save some of you some time. Good luck, and happy coding!
Tags:code, coding, development, else, endif, if, php, then, tips
Leave Comment » | 0 views | Posted in development, php
Digg This Story
September 6th, 2008 by
Daniel Costalis
(Who am I?)
The Republican party had a company donate $5000 to a local school to have 103 McCain supporting students to inflate over 100,000 balloons to drop at the Republican National Convention. It was a pretty cool sight. If nothing else, the Republicans have the Democrats beat on balloon dropping as Chris Matthews pointed out. Maybe the balloons were to help mask the blatant lies that their speeches held. In fact, they did interfere with one of MSNBC’s reporters from commenting afterwards. The RNC did release that the way their speeches and videos were designed was to make sure there was no space in between to allow for network commentary… They relied on the fact that viewers would tune out as soon as the sppeches were over, and wouldn’t have a chance for the reporters to let them know about the false information provided in their speeches.
Smart move I guess, but I’m so sick of shady politics.
Tags:2008 election, election, mccain, obama, random, republican, rnc
Leave Comment » | 1 views | Posted in random
Digg This Story
September 2nd, 2008 by
Daniel Costalis
(Who am I?)
I’m impressed. It’s everything I would have expected from Google, and more.
The Google Chrome Beta was just released, and I don’t think I’ll be going back to Firefox any time soon. It’s fast. It’s stable. It’s pretty.
The first thing you’ll notice is the layout. Tabs are located above everything in the title bar area, and because of this, you get more screen space for browsing. It also just makes sense. (more on this later). The status bar is non existant as well, freeing up even more screen space. Instead, when you hover over a URL, a small bar pops up that tells you where you’re going, the unobtrusivly disappears. Very classy, very well-thought out.
More on the tabs: Each tab has it’s own process now, which you can see by viewing the built in task manager. From this, you can view how much memory each tab and each plugin are using… and kill the process if it gets out of hand. Gone are the days of Firefox and IE using 200+ megabytes of memory… even though you’ve closed all your tabs. They’ve taken the concept of tabs, and make them the king. Instead of having a browser filled with tabs, you have browser tabs that are grouped together by a slick interface. That may sound like the same thing to some of you… but it really isn’t.
I ran a few tests on it, including the Acid3 and Acid2 test. It did better than Firefox in the Acid3 test, scoring a 78/100 (not bad!), and passes the Acid2 test with flying colors, as expected at this point.
The javascript speed is pretty exciting. After running about 6 tests, Chrome performs anywhere from 4 to 25 times faster than Firefox, and is right on par with Safari, being anywhere to 50% to 120% of the speed, depending on the test. It’s even 2 to 5 times faster than (*cough*) unbloated IE6.
The beta release is Windows only at this point at http://www.google.com/chrome , but source code is available for those who want to build it on linux at http://www.chromium.org
Tags:chrome, firefox, google, news, safari, tips, web 2.0, web browser
Leave Comment » | 6 views | Posted in development, news, web 2.0, windows
Digg This Story
September 2nd, 2008 by
Daniel Costalis
(Who am I?)
Another Edit: To encourage discussion, a second prize has been added. The person who I feel contributes the most to the solving of this (via comments) will also receive a prize of $25 USD, even if he/she doesn’t come up with the correct answer. This is determined solely by me, and will only be given out if I feel someone has contributed. The winner may very well receive this prize too if the discussion I see warrants it.
No joke. Very simple. Send an email to dcostalis@gmail.com with the message that this contains, and I’ll send you $100 USD if yours is the first e-mail i get, via the method you choose. If you don’t think you can do it on your own… send it off to a friend. They’ll probably split it with you if you help…
Good luck to all, and don’t be greedy… spread this around. Someone elses crackpot logic may just be the jump your brain needs.
Edit: No, you do not win if you tell me it says “HI”. When you get the correct message, you will know, trust me.

7 Comments » | 367 views | Posted in development
Digg This Story
September 1st, 2008 by
Daniel Costalis
(Who am I?)

The mission of the Chicago Anti-Hunger Federation is to alleviate hunger in metropolitan Chicago through the distribution of high-quality food; education; advocacy; culinary arts and other employment training.
The Chicago Anti-Hunger Federation has been around since 1990, and has distributed millions of dollars of good, healthy food across Chicago. As we enter the waning years of the first decade of the 21st century, they felt it was time their website better reflected todays standards. Starting from scratch, we redesigned the site, and gave it a more appealing, colorful, look, with a simple navigation scheme that anyone can understand.
The site soft-launched over the weekend, and after having the chance to test it thoroughly, I am proud to announce the launch of the new antihunger.org.
Tags:charity, design, development, domains, launch, web design
1 Comment » | 5 views | Posted in B2B, Blogroll, design, development, domains, portfolio
Digg This Story