<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Doing My Best... a Web Developers Blog &#187; Tips</title>
	<atom:link href="http://www.iwilldomybest.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iwilldomybest.com</link>
	<description>Ranging from PHP &#38; MySQL to Random Crap from the internet, I got it all here.</description>
	<lastBuildDate>Wed, 10 Nov 2010 01:08:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Make an Impact</title>
		<link>http://www.iwilldomybest.com/2009/06/make-an-impact/</link>
		<comments>http://www.iwilldomybest.com/2009/06/make-an-impact/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 08:36:11 +0000</pubDate>
		<dc:creator>dschreck</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Personal Life]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[impact]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://www.iwilldomybest.com/?p=86</guid>
		<description><![CDATA[Day 3, you better have your shit together, and you should be swinging for the fences. ]]></description>
			<content:encoded><![CDATA[<p>Recently, it has come to my attention that not all developers have the ability to make an impact.</p>
<p>But that begs the question, what does making an impact mean?</p>
<p>Making an impact.</p>
<p>It's coming out the door - swinging. So much of a developers role, especially in a start up, is determined by their first 3 days. Day 1, yes, come in, settle down, welcome aboard. Day 2, start asking all of the questions you had from day 1, and for heavens sake, do something besides look busy.</p>
<p>Day 3, you better have your shit together, and you should be swinging for the fences.</p>
<p>Don't ask for something to do, demand a project. And while you're doing, don't ask questions the very second you think you don't know something.</p>
<p>Look for the answer first.</p>
<p>It's this mentality that I find so damn frustrating - all of the answers should be in the code base. Run a damn grep on your project base, and find an answer. There's no excuse for any mid, to upper mid level programmer to be asking stupid questions. By stupid question, I'm refering to in the inabilty to traverse the code base in search of functions, methods, answers.</p>
<p>Make an impact, 3 days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwilldomybest.com/2009/06/make-an-impact/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Modrewrite and Short Urls &#8211; What you really want to know.</title>
		<link>http://www.iwilldomybest.com/2009/01/modrewrite-and-short-urls-htaccess-file-tip/</link>
		<comments>http://www.iwilldomybest.com/2009/01/modrewrite-and-short-urls-htaccess-file-tip/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 11:07:44 +0000</pubDate>
		<dc:creator>dschreck</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod rewrite]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.iwilldomybest.com/?p=77</guid>
		<description><![CDATA[I recently opened up an old .htaccess and I was struck with the memory of how much it sucked trying to Google search for some real, working, answers on making short urls. So here you go, my quick tip on what you really want to know about mod_rewrite. If you want an actual explanation of [...]]]></description>
			<content:encoded><![CDATA[<p>I recently opened up an old <a title="WikiPedia - Htaccess" href="http://en.wikipedia.org/wiki/Htaccess" target="_blank">.htaccess</a> and I was struck with the memory of how much it sucked trying to Google search for some real, working, answers on making short urls.</p>
<p>So here you go, my quick tip on what you really want to know about <a title="ApacheDocs - Mod_rewrite" href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html" target="_blank">mod_rewrite</a>.</p>
<p><span id="more-77"></span></p>
<p>If you want an actual explanation of what is going on here it's at the bottom.</p>
<p><strong>Solution 1:</strong></p>
<p><code>File: .htaccess</code></p>
<pre class="brush:shell">
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) /index.php [L]
</pre>
<p><code>File: index.php</code></p>
<pre class="brush:php">

$urlArray = explode("/",$_SERVER['REQUEST_URI']);

array_shift($urlArray); // Gets rid of the blank first param.
</pre>
<p>Now you have an array with all of your parts, and you can map them accordingly.</p>
<p><strong>Solution 1.a (more elegant):</strong><br />
<code>File: .htaccess</code></p>
<pre class="brush:shell">
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</pre>
<p>That version just checks to make sure the module is installed.</p>
<p><strong>Solution 2:</strong><br />
If you have just a couple of pages that you want to look prettier:</p>
<p><code>File: .htaccess</code></p>
<pre class="brush: bash; title: ; notranslate">
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^home$ index.php
RewriteRule ^about$ about.php
</pre>
<p>And you just keep adding <code>RewriteRule</code>'s for each page. This is really only helpful when you just have a set of static looking pages for a site.</p>
<p><strong>Explanation:</strong></p>
<dl>
<dt>Options +FollowSymLinks</dt>
<dd>Tells Apache to follow sym links (usually on anyways...)</dd>
<dt>RewriteEngine on</dt>
<dd>Tells apache to turn on the RewriteEngine for this folder</dd>
<dt>RewriteCond %{REQUEST_FILENAME} !-f</dt>
<dd>Read this as: Condtion, If the file we're requesting is not a file...</dd>
<dt>RewriteCond %{REQUEST_FILENAME} !-d</dt>
<dd>Read this as: Condtion, If the file we're requesting is not a directory...</dd>
<dt>RewriteRule . /index.php [L]</dt>
<dd>Then Rewrite this url to index.php ([L] forces it to be the last redirect)</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://www.iwilldomybest.com/2009/01/modrewrite-and-short-urls-htaccess-file-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Professional PHP</title>
		<link>http://www.iwilldomybest.com/2009/01/professional-php/</link>
		<comments>http://www.iwilldomybest.com/2009/01/professional-php/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 16:05:18 +0000</pubDate>
		<dc:creator>dschreck</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.iwilldomybest.com/?p=61</guid>
		<description><![CDATA[It's important to remember what sets a professional PHP developer apart from the pack that floods your average help channel. Too often I run into reviewing or helping a "professional" developer, and I can't help but mutter "you're doing it wrong..." I feel the most important attribute that separates one developer from another is when [...]]]></description>
			<content:encoded><![CDATA[<p>It's important to remember what sets a professional PHP developer apart from the pack that floods your average help channel.</p>
<p>Too often I run into reviewing or helping a "professional" developer, and I can't help but mutter "you're doing it wrong..."</p>
<p><span id="more-61"></span></p>
<p>I feel the most important attribute that separates one developer from another is when they write for usability and maintainability.</p>
<p>So let's take a look at some extremely simple steps you can take to make your project's code more flexible.</p>
<p>1. For the love of all that there is, seperate your header and footer files. Yes, I'm still seeing this happen, often. All content that is above your generated page needs to go into a header file, and all the content below it into a footer file. So when you need to modify one line, you do it only once.</p>
<pre class="brush:php">
&lt;?php
require_once(dirname(__FILE__).'/includes/header.php');
?&gt;
<div id='content'>
&lt;?php
	// script runs
?&gt;
</div>

&lt;?php
require_once(dirname(__FILE__).'/includes/footer.php');
?&gt;
</pre>
<p>2. Create a function to generate your navigation. And when I say generate, I mean you give it some flexibility as well. This can be done even with the smallest of sites. Example:</p>
<pre class="brush:php">
&lt;?php
$site_pages = array();
$site_pages[] = array('text' =&gt; 'home', 'link' =&gt; 'home.php');
$site_pages[] = array('text' =&gt; 'about', 'link' =&gt; 'about.php');
$site_pages[] = array('text' =&gt; 'partner', 'link' =&gt; 'http://www.example.domain.com/');

function buildNav($links)
{
	$output = '';
	foreach($links as $page)
	{
		$output .= "&lt;a href=\"{$page['link']}\" title=\"{$page['text']}\"&gt;{$page['text']}&lt;/a&gt;\n";
	}
 	return $output;
}
?&gt;
</pre>
<p>The example above could easily be modified to allow optional values to the array, like <code>'enabled' =&gt; false</code> to turn off a link. Or you could define a link "template", and use <code>str_replace()</code> to substitute values.</p>
<p>This means if you, or the customer (with any know how) can quickly update the links at any time. For more advanced sites/projects this can obviously become more complicated, but it saves even more time.</p>
<p>3. If you're not going to use OOP, at least use functions. Any common task or specific sequence should be placed in it's own function. An example would be our navigation function from #2. Another example would be running a query for a specific item. If you ever need to modify your table structure you'll regret having to hunt down all of your inline queries.</p>
<p>4. When you create 'admin' features, take the 5 minutes to create a function that actually checks if the person accessing that "super hidden" directory filled with scripts that just accept anything.</p>
<p>I've seen this happen even on large global community sites.</p>
<p>Some developers will stuff their admin scripts in a folder such as /admin/, and just assume that if data is posted there then it's ok.</p>
<p>The least you should do is place a session check, and place it in a function.</p>
<pre class="brush:php">
&lt;?php
function isAdmin()
{
	if(!isset($_SESSION['user_name']) || !isset($_SESSION['user_id']))
	{
		return false;
	}
	else
	{
		$sql = "SELECT COUNT(*) as cnt FROM user_table WHERE user_id = ".intval($_SESSION['user_id']);
		// do the query, check it, etc.
		return true;
	}
}
?&gt;
</pre>
<p>Then when it comes time to run your script, simply:</p>
<pre class="brush:php">
&lt;?php
if(isAdmin() === false)
{
	die('Log back in');
}
?&gt;
</pre>
<p>5. Create a wrapper for handling escape strings. If you're not using a database class (like PDO) to handle this, you'll need to do this.</p>
<p>Just assume that your client could have their PHP configuration change, or they change hosts, or any possible combination of changes take place.</p>
<p>Create a simple wrapper that will check of magic quotes, and escape for your database insert.</p>
<pre class="brush:php">
&lt;?php
function cleanString($input)
{
	if(get_magic_quotes_gpc())
	{
		$input = stripslashes($input);
	}
	$output = mysql_real_escape_string(trim($input));

	return $output;
}
?&gt;
</pre>
<p>6. Create a configuration file so you can update common yet critical variables. An example of this would be paths. Your system quickly gains adaptability if you just create a defines.php file, and place in there your simple variables.</p>
<p>The overall approach you should have to any project you take is that you should use an establish tool chain you have developed. It doesn't take much time or effort to create a simple set of classes that can handle just about any thing you need to create. If you wish to use functions, you can do the same. The idea is that you write once, and write it in such a manner that you can tweak it later on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwilldomybest.com/2009/01/professional-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &amp; MySQL Tip #2 &#8211; Better Way of Pagination</title>
		<link>http://www.iwilldomybest.com/2008/03/php-mysql-tip-2-better-way-of-pagination/</link>
		<comments>http://www.iwilldomybest.com/2008/03/php-mysql-tip-2-better-way-of-pagination/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 04:30:27 +0000</pubDate>
		<dc:creator>dschreck</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/03/15/php-mysql-tip-better-way-of-pagination/</guid>
		<description><![CDATA[I've seen this come up a few times in #php on irc.gamesurge.net - how to find the total number of rows found, while using the LIMIT clause on a query. I've seen people respond with some seriously incorrect solutions, such as 'Simply load all of the results into an array and only show X amount' [...]]]></description>
			<content:encoded><![CDATA[<p>I've seen this come up a few times in #php on irc.gamesurge.net - how to find the total number of rows found, while using the LIMIT clause on a query.</p>
<p>I've seen people respond with some seriously incorrect solutions, such as 'Simply load all of the results into an array and only show X amount' or 'Simple run another query without the LIMIT clause and count those rows.'</p>
<p>Those two, common, solutions are sadly not the best solution.</p>
<p>Read on to discover my solution.</p>
<p><span id="more-16"></span></p>
<p>Take for example the following query:</p>
<p><code>$sql = "SELECT id as id, name as name, full_title as title FROM articles ORDER BY id LIMIT 0,10";</code></p>
<p>Now, that looks all fine and dandy, you have probably used something very similar to that query many times. Now, say we want to actually show how many articles we have in our database?</p>
<p>We would simply change that query to:</p>
<p><code><br />
$sql = "SELECT SQL_CALC_FOUND_ROWS id as id, name as name, full_title as title FROM articles ORDER BY id LIMIT 0,10";<br />
$get = mysql_query($sql) or die(mysql_error());<br />
$sql_2 = "SELECT FOUND_ROWS();";<br />
$found_rows = mysql_query($sql_2) or die(mysql_error());<br />
</code></p>
<p>Now yes, we're running two queries, but we're not actually queries against any rows. So therefore, this solution is more elegant and ultimately more important, it's not attempting to scan any tables for data.</p>
<p>So next time you're looking to do a quick and pagination script, go ahead and try this technique out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwilldomybest.com/2008/03/php-mysql-tip-2-better-way-of-pagination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problem Solving &#8211; guide to PHP programming and debugging.</title>
		<link>http://www.iwilldomybest.com/2008/03/problem-solving-guide-to-php-programming-and-debugging/</link>
		<comments>http://www.iwilldomybest.com/2008/03/problem-solving-guide-to-php-programming-and-debugging/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 07:15:21 +0000</pubDate>
		<dc:creator>dschreck</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/03/02/problem-solving-guide-to-php-programming-and-debugging/</guid>
		<description><![CDATA[Problem solving forms part of thinking. Interesting... so, if so many web devs and IT personnel have such a problem with problem solving, perhaps they're just not thinking? Let's explore some of the problems I've seen people encounter, and how I was baffled they lacked the problem solving skills to complete their tasks. All too [...]]]></description>
			<content:encoded><![CDATA[<p>Problem solving forms part of thinking.</p>
<p>Interesting... so, if so many web devs and IT personnel have such a problem with problem solving, perhaps they're just not thinking? Let's explore some of the problems I've seen people encounter, and how I was baffled they lacked the problem solving skills to complete their tasks.</p>
<p><span id="more-15"></span></p>
<p>All too often, a situation will appear in just one or two flavors. One being, "Hey, this should be working but it's not..." or, "Hey, I'm stuck." Sometimes you get the nice and juicy combo. But, that being said, let's explore how I most commonly find myself approaching these two generic scenarios.</p>
<p><strong>Number one, "Hey, this should be working but it's not..."</strong></p>
<p>Whenever you get to this point, that usually means a couple things:</p>
<ol>
<li>I have a pretty good idea on what <em>should </em>be happening</li>
<li>I know how it should be done</li>
<li>I've already solved this problem before, but this time it doesn't seem to be working</li>
</ol>
<p>Number 3 is always the worst, because as a programmer, you always think back to the last time you faced a similar problem, and basically copy the way you fixed it before. If that is the case, examine what's different this time... versions, updates, different variables, etc etc, these all have an impact.</p>
<p>And what it really comes down to, is back tracking all of your steps.</p>
<ul>
<li>Did I upload the latest version of the PHP script?
<ul>
<li>And if so, are the changes reflected on the server side?</li>
</ul>
</li>
<li>Has someone else made changes to the files in use?</li>
<li>Have a double checked the process against my flow charts?</li>
<li>Have I tried basic debugging?
<ul>
<li>This means, rather briefly:
<ul>
<li>Echo out the variables BEFORE they're passed or referenced</li>
<li>AND AFTER they are passed or referenced.</li>
<li>Have I done a var_dump()</li>
<li>Have I turned on error_reporting(E_ALL);</li>
<li>Have I checked my error_log</li>
<li>Have I checked my mysql_error();</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>If you go through a simple list like that in your mind, you can quickly determine where you're missing a step.</p>
<p>And please, for the love of all that is holy, please, don't be afraid to TRY something even if you're not sure it'll work. You should take the basic steps to plot out your thoughts before you begin to code. For me, that usually means getting out some paper and a pen, and sketch out my idea with some notes.</p>
<p>Then I begin to code.</p>
<p>If I ever get lost in this new idea of mine, I refer to my original plan. If I realize then that my original plan was FUBAR, I simply make the adjustments to my sketch, and keep on going.</p>
<p>I feel that most web developers somehow feel that they can just jump straight into a project without any planning. It simply doesn't happen. All "great" projects, they start with a little planning. Sure, maybe they didn't have a road map, version control, diagrams, database designs, ticketing systems, et cetera, but they at least had an idea. And I guarantee that idea was  <em>at least </em>written down in pseudo code.</p>
<p>Again, the idea here is that you HAVE a plan, and you know how things should work, so stick to your plan. You run into the problem of "It should work but it's not" when you've altered a step somewhere. Check your debugs, check your error logs, check your plan. Rinse repeat until you go mad. And don't be afraid to ask for some fresh eyes on the problem.</p>
<p><strong>Number Two, "I'm stuck."</strong></p>
<p>This comes down to just general programming knowledge. Or rather, how well you understand programming logic. I will often tell people, any one can be a programmer; in fact, everyone is a programmer. Programming is just solving a problem with at last one solution. You do this by breaking it down.</p>
<p><span style="text-decoration: underline;">Identify the problem</span> - <em>What do I need to accomplish?</em><br />
<span style="text-decoration: underline;">Determine the order</span> - <em>What needs to happen to solve this problem?</em><br />
<span style="text-decoration: underline;">How do I apply my solution</span> - <em>What's my plan of action?</em></p>
<p>Let's take for example, the problem of creating an E-Mail list manager.</p>
<p><span style="text-decoration: underline;">Identifying the problem</span> - I know what the solution is -- an email list manager. That's my solution, now what's the problem?Ã‚Â  Ok, this e-mail list manager is going to have a set of emails that it sends updates to everyone month. So... the problem is I need to find out how and where the e-mail addresses are stored, and I need to create a way for them to automatically be sent.</p>
<p><span style="text-decoration: underline;">Determine the order</span> - Well, I kind of already figured that out. I need to:</p>
<ol>
<li>Get the E-Mail Address
<ol>
<li>Make sure it's valid</li>
<li>Make sure they are opted in</li>
</ol>
</li>
<li>Add that Validated E-Mail address to the 'Send To' array</li>
<li>Create the body of my E-Mail
<ol>
<li>One for Plain Text</li>
<li>One for HTML</li>
</ol>
</li>
<li>Apply any templating system that may be needed</li>
<li>Do a foreach() on the 'Send To' array
<ol>
<li>Then send the emails</li>
</ol>
</li>
</ol>
<p><span style="text-decoration: underline;">How do I apply my solution</span> - Well, I'm going to need a CRON script that will run once a month. I will need to create a debugging / status message system so that I can record how many e-mails got sent out, and on what date, and to whom. It's pretty straight forward from there. Create the PHP script, be sure to apply the CLI items, and boom. Start.</p>
<p>What I'm trying to get across here, is that you need to approach things not as strictly code, but as a single thought. This is what I want, this is how I do it.</p>
<p>When you're running a program, you're not just running code, you're running someone's thoughts.Ã‚Â  That's the beauty in programming, it's not just about the code, it's about someone else getting to see into your mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwilldomybest.com/2008/03/problem-solving-guide-to-php-programming-and-debugging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

