<?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>Tampa Site Design &#187; Coding</title>
	<atom:link href="http://www.tampasitedesign.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tampasitedesign.com</link>
	<description>Chronicles of Website Design</description>
	<lastBuildDate>Sun, 08 Aug 2010 19:36:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SEO tips for new sites</title>
		<link>http://www.tampasitedesign.com/seo-tips-for-new-sites/</link>
		<comments>http://www.tampasitedesign.com/seo-tips-for-new-sites/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 05:10:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[capitalization]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[multiple sites]]></category>
		<category><![CDATA[new sites]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=64</guid>
		<description><![CDATA[Over the years, I&#8217;ve had to apply SEO to a wide variety of sites and it goes without saying, the best SEO is implemented when the site is built!
Nothing is worse than having to build around a messy site. What I mean by messy is lengthy URLS with pointless characters and crazy dynamic URLs! So [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, I&#8217;ve had to apply SEO to a wide variety of sites and it goes without saying, the best SEO is implemented when the site is built!</p>
<p>Nothing is worse than having to build around a messy site. What I mean by messy is lengthy URLS with pointless characters and crazy dynamic URLs! So here are my tips on creating an SEO-friendly site:</p>
<p>1) Use static URLs when possible. This might not be possible with really large sites, but if your site has less than 50 pages and doesn&#8217;t require new pages to be created all the time, this is definitely the way to go. This is definitely the easiest way and best for SEO. The second best is using an htaccess redirect to use a name in the URL and pass it as a GET variable. Something like this:</p>
<p>http://www.tampacreations.com/portfolio</p>
<p>In this case, portfolio is being passed as a GET variable, and you should always check this against an array of acceptable values! Combine that htaccess code with the proper rewrite condition to tack on the www, and handle forward slashes at the end too. Would you like to see it? Here&#8217;s the code I&#8217;m using:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Options <span style="color: #339933;">-</span>Indexes
RewriteEngine On
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_HOST<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^www\<span style="color: #339933;">.</span>yourdomain\<span style="color: #339933;">.</span>com$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.yourdomain.com/$1 [R=301,L]</span>
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_HOST<span style="color: #009900;">&#125;</span> ^<span style="color: #009900;">&#40;</span>www<span style="color: #339933;">.</span><span style="color: #009900;">&#41;</span>?yourdomain\<span style="color: #339933;">.</span>com$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.yourdomain.com/$1 [R=301,L]</span>
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_HOST<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^www\<span style="color: #339933;">.</span>yourdomain\<span style="color: #339933;">.</span>com$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.yourdomain.com/$1 [R=301,L]</span>
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>^<span style="color: #339933;">/</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>?$ index<span style="color: #339933;">.</span>php?page<span style="color: #339933;">=</span>$<span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#91;</span>L<span style="color: #009900;">&#93;</span></pre></div></div>

<p>So that&#8217;s the second best option if you have to go with dynamic URLs and it works pretty well! I believe I&#8217;m using PHP, then, to set 404 status of not found domains. </p>
<p>2) Search Pages can be a nightmare! Search pages can be problematic because they&#8217;re dynamic by nature and can end up having lots of variables in them. I think the trick here is to have a few of them indexed (the simple ones) and list those in your sitemap. The other ones you can let Google figure out or just deny it access.</p>
<p>3) Watch out for capitalization! Capitalization counts in URLs (just not the domain), so if I were to have a page Portfolio.html and portfolio.html, those are two different pages! If you&#8217;re using dynamic URLs, this can become a big problem with duplicate content.</p>
<p>4) Multiple websites. Lot of e-commerce site owners have the mentality that duplicating their entire store 5 times and putting it on 5 different domains helps their SEO out. Probably not a good idea. What ends up happening is since most stores have a lot of products, the owners use the same descriptions, same images, everything, and all the sites end up having duplicated content issues! I happy to report that a client I worked with who had this issue across 4 domains, downsized to one domain, and has twice as much traffic now after doing so in about 12 months. It takes time, but it&#8217;s worth it. The only way you should keep 5 different stores is if all the stores are different! Different product titles, different descriptions for each page, keywords, product descriptions, shipping text, contact text, etc. etc. etc. Everything should be completely different if you want to rank well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/seo-tips-for-new-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Line Breaks in Textarea with PHP</title>
		<link>http://www.tampasitedesign.com/line-breaks-in-textarea-with-php/</link>
		<comments>http://www.tampasitedesign.com/line-breaks-in-textarea-with-php/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 19:38:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[line breaks]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[textarea]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=60</guid>
		<description><![CDATA[There seems to be a  lot of confusion surrounding line breaks. You&#8217;re probably familiar with this:
\r\n
This is a line break, right? Well it can be. It depends on if it&#8217;s processed as normal text or not.
Let&#8217;s say a user is submitting a form and in the textarea, they add some line breaks. Let&#8217;s say they [...]]]></description>
			<content:encoded><![CDATA[<p>There seems to be a  lot of confusion surrounding line breaks. You&#8217;re probably familiar with this:</p>
<p>\r\n</p>
<p>This is a line break, right? Well it can be. I<strong>t depends on if it&#8217;s processed as normal text or not.</strong></p>
<p>Let&#8217;s say a user is submitting a form and in the textarea, they add some line breaks. Let&#8217;s say they miss a field and  you have the form printing out it&#8217;s own POST values (so they don&#8217;t accidentally lose anything), like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;textarea cols=&quot;32&quot; rows=&quot;6&quot; name=&quot;description&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;</pre></div></div>

<p>This is pretty simple, it&#8217;s just printing out the value of the posted description variable. But like I said a minute ago, if they had put line breaks in their textarea, their information will be posted in the textarea again, but it will look like this:</p>
<p>Information on Line 1\r\nInformation on Line 2</p>
<p>The problem here is that the \r\n is getting changed to normal text. To change it back, we replace it with itself, but with double quotes, returning it back to code as opposed to normal text. Here&#8217;s the final result:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;textarea name=&quot;description&quot; rows=&quot;6&quot; cols=&quot;32&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\r\n'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/line-breaks-in-textarea-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Website Color Schemes</title>
		<link>http://www.tampasitedesign.com/website-color-schemes/</link>
		<comments>http://www.tampasitedesign.com/website-color-schemes/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 07:04:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=49</guid>
		<description><![CDATA[Today I wanted to hit on website color schemes, sometimes a difficult subject for clients. The main purpose of a color scheme isn&#8217;t necessarily to make your website better looking (although it usually doesn&#8217;t hurt), but actually to assist your website in accomplishing its main goals! Different colors have different preconceived meanings attached to them; [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to hit on website color schemes, sometimes a difficult subject for clients. The main purpose of a color scheme isn&#8217;t necessarily to make your website better looking (although it usually doesn&#8217;t hurt), but actually to assist your website in accomplishing its main goals! Different colors have different preconceived meanings attached to them; and those differ depending on your audience. So, our primary step is to establish our target audience, more specifically, our target geographic region since color meanings differ the most between countries (did you know the color white in Japan is associated with death?).</p>
<p>For our purposes, we&#8217;ll pretend your audience is strictly within the United States. The next step then is to think about what the main goal of your website is and how the colors will help reflect the attitude your website needs to achieve its goals. Here are some examples of associations:</p>
<ol>
<li>Saturated colors are good for youth related items, and semi-saturated for fun, exhilarating, etc.</li>
<li>Pastel colors signify peace, relaxation, etc.</li>
<li>Dark colors can be good for evil, secret, technological, etc.</li>
</ol>
<p>You also have some specific colors with some overall associations. Not to say they&#8217;re specific to these in particular, but they work well for what they&#8217;re paired with:</p>
<ol>
<li>Royal/Dark Blue is typically associated with corporate.</li>
<li>Red associated with extreme</li>
<li>White associated with large/enterprise</li>
<li>Green associated with eccentric</li>
</ol>
<p>These are just some examples. To find more, visit popular websites and see what they&#8217;re using to influence the vibe of their visitors. Influcing a vibe can be very helpful in raising conversions and accomplishing goals so when you&#8217;re thinking about your next color scheme for your website, be sure to put some extra thought and research into it instead of just going with your favorite color (pink).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/website-color-schemes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login Redirect Design</title>
		<link>http://www.tampasitedesign.com/login-redirect-design/</link>
		<comments>http://www.tampasitedesign.com/login-redirect-design/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 05:40:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=39</guid>
		<description><![CDATA[Wanted to quickly touch on a UI design, or rather, lack there of, that I encounter often enough on websites which can be really annoying. Say you get to a website that you&#8217;re a member of and the link you click on requires you to be a member and login&#8230; and you do (login)&#8230; and [...]]]></description>
			<content:encoded><![CDATA[<p>Wanted to quickly touch on a UI design, or rather, lack there of, that I encounter often enough on websites which can be really annoying. Say you get to a website that you&#8217;re a member of and the link you click on requires you to be a member and login&#8230; and you do (login)&#8230; and conveniently enough, you&#8217;re taken to some main account screen &#8211; not the page you were looking for (where that links goes).</p>
<p>Now a little tip for users, most websites use sessions to keep you logged in, and in most cases you can use your browser&#8217;s back button to go back to the original page you requested before it redirected you and refresh that page, and you&#8217;re there. But it shouldn&#8217;t have to be that way. If you&#8217;re a developer, you need to think ahead in your coding and login script. You&#8217;ll need to implement some way of redirecting the user to the protected page that they originally requested after they login. This is easier said than done sometimes, especially if your script is already written.</p>
<p>Some extra tools to use here if you&#8217;re in a tight spot for coding: Cookies and Header Redirects. Let&#8217;s say you&#8217;re script is already written&#8230; it looks something like this:</p>
<ol>
<li>Person clicks on link to a protected page on the site, requesting the protected page</li>
<li>You have some code that either forwards them to a login page or displays a login page</li>
<li>The login and it automatically goes to/displays a main account page.</li>
</ol>
<p>It can be tough to implement and carry variables over these pages and between files, so storing and passing the initially requested URL can be difficult. Although, using Cookies can work pretty well. The basic idea is to interrupt the second step. When the code is forwarding them to a login page/content, it&#8217;ll first check to see what the URL is and store it as a Cookie variable. Then when they are logging in, before it sends them off to the main account page, we can check that Cookie to see if it&#8217;s set and what&#8217;s in there. It would be smart to compare that value to an array of allowed values and forward them to the necessary page/content afterwards, if it matches something in your control array. To store that URL, I would use a regular expression to grab the page name and since it&#8217;s likely that some of your protected pages will have GET vars attached, take those variables and store them in a separate cookie, later appending them if the page matches what&#8217;s in your control array. You shouldn&#8217;t really need to deal with POST variables between a non-protected and a protected requested URL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/login-redirect-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Next and Previous Buttons for Search Query Results</title>
		<link>http://www.tampasitedesign.com/php-next-and-previous-buttons-for-search-query-results/</link>
		<comments>http://www.tampasitedesign.com/php-next-and-previous-buttons-for-search-query-results/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 19:29:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[next]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[previous]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[results]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=17</guid>
		<description><![CDATA[What we&#8217;re talking about today is how to make those Next, Previous, and Number buttons for search results&#8230;

Usually found at the bottom of sites like Google and eBay. There&#8217;s two pieces of data we need:

Start At / Offset Value (usually set in the URL)
Limit (set internally or in the URL)

Being we only need these two [...]]]></description>
			<content:encoded><![CDATA[<p>What we&#8217;re talking about today is how to make those Next, Previous, and Number buttons for search results&#8230;
<p><img src="http://www.tampasitedesign.com/images/search_results.gif" alt="search results php" /></p>
<p>Usually found at the bottom of sites like Google and eBay. There&#8217;s two pieces of data we need:</p>
<ol>
<li>Start At / Offset Value (usually set in the URL)</li>
<li>Limit (set internally or in the URL)</li>
</ol>
<p>Being we only need these two variables, you might think this is a pretty simple task, but creating some well-working links takes a fair bit of code. For this example, we&#8217;ll define the limit internally, but still use dynamic code so it could be used as a GET variable.</p>
<p>The first issue we have in defining links to a different offset is in the URL itself:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">index<span style="color: #339933;">.</span>php?keywords<span style="color: #339933;">=</span>tampawebsitedesign<span style="color: #339933;">&amp;</span>start_at<span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">&amp;</span>order_by<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span></pre></div></div>

<p>As you can see here, our start_at variable is equal to 10, which is what we&#8217;ll put in our sql string. The problem is when they hit the next page button that sets it to 20. This impacts your links because you have to securely redefine the offset variable without loosing the other variables. Here&#8217;s how we would do that:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// get the current URL</span>
<span style="color: #000088;">$current_url</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTPS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;https://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// replace the start_at variable and value</span>
<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/\&amp;start_at=[0-9]*/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$back_forward_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #000088;">$current_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here we&#8217;ve basically stripped our start_at variable and value from the URL. Moving forward, we need to generate our Next and Previous buttons. This part is pretty simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$start_at</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// set the start_at variable equal to the URL value</span>
<span style="color: #000088;">$limit_num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// set the limit equal to 10 (or whatever you want)</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// calculate the previous amount and link</span>
<span style="color: #000088;">$previous_amt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start_at</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$limit_num</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$previous_link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$back_forward_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;start_at='</span><span style="color: #339933;">.</span><span style="color: #000088;">$previous_amt</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Previous&lt;/a&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// calculate the next amount and link </span>
<span style="color: #000088;">$next_amt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start_at</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$limit_num</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$next_link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$back_forward_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;start_at='</span><span style="color: #339933;">.</span><span style="color: #000088;">$next_amt</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Next&lt;/a&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if statements which set the links equal to nothing</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_at</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$previous_link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_at</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$limit_num</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$total_results</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$next_link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At this point we have our Next and Previous button variables taken care of. Now we need to make the numbers in the middle. Something to note, however, is that if you have 100 pages of results returned, we don&#8217;t want to print out 100 numbers, we only want to print out 9 or 10 or around there. So we need to install a range of if statements that will make sure we put in the right amount.</p>
<p>The first step is to create a function which our total pages and current page can calculate from:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// shared function for calculations</span>
<span style="color: #000000; font-weight: bold;">function</span> find_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tr</span><span style="color: #339933;">,</span><span style="color: #000088;">$ln</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pages_total</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tr</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$ln</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// intval rounds any decimal down to its integer value</span>
	<span style="color: #000088;">$match_results</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pages_total</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$ln</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$match_results</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$tr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$pages_total</span><span style="color: #339933;">--;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$pages_total</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// find total pages</span>
<span style="color: #000088;">$pages_total</span> <span style="color: #339933;">=</span> find_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$total_results</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit_num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find current page</span>
<span style="color: #000088;">$curr_page</span> <span style="color: #339933;">=</span> find_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_at</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit_num</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></div></div>

<p>Next, we put in our if statements to set two new variables: $page_link and $loop.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pages_total</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$page_link</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$loop</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pages_total</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curr_page</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$pages_total</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$page_link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pages_total</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$loop</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curr_page</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$page_link</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$loop</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$page_link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$curr_page</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$loop</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Just about done! Now, we&#8217;ll loop through and save our links to a variable called $middle_links. I&#8217;ve taken the extra step to add in a styling class for an active link versus a non-active link.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$loop</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$page_start_at</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page_link</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$limit_num</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$limit_num</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curr_page</span><span style="color: #339933;">==</span><span style="color: #000088;">$page_link</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">;</span><span style="color: #000088;">$link_class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'page_btn_active'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$link_class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'page_btn'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$middle_links</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$back_forward_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;start_at='</span><span style="color: #339933;">.</span><span style="color: #000088;">$page_start_at</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; class=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$link_class</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$page_link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; | '</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$page_link</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, we&#8217;ll put everything together and print it out. We have to do one last check before our print which is taking off the extra &#8221; | &#8221; from our loop if there is no Next button. You can also see that we&#8217;ve added a div to style the entire link bar.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$next_link</span><span style="color: #339933;">==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$middle_links</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$middle_links</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// take out the extra &quot; | &quot; if we have no Next button</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'&lt;div id=&quot;page_link_bar&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$previous_link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$middle_links</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$next_link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// put everything together</span></pre></div></div>

<p>There you have it! </p>
<p>Some hints to help you along as well:</p>
<ul>
<li>If the start_at value is not set in the URL, you need to set that to 0</li>
<li>Always do verification on your REQUEST (GET &amp; POST) variables. is_numeric() function works well for the start_at variable.</li>
<li>To make it work, you&#8217;ll just append your variables into your MySQL statement using LIMIT.

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">SELECT <span style="color: #339933;">*</span> WHERE id<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span> ORDER BY id DESC LIMIT <span style="color: #000088;">$start_at</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit_num</span></pre></div></div>

</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/php-next-and-previous-buttons-for-search-query-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Efficient Form Direction with PHP</title>
		<link>http://www.tampasitedesign.com/efficient-form-direction-with-php/</link>
		<comments>http://www.tampasitedesign.com/efficient-form-direction-with-php/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 09:58:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=13</guid>
		<description><![CDATA[A really common type of PHP script is an add/edit/delete form. This is typically used in a back-end content management system for an administrator to add/edit/delete information. For example, a news editor with three fields:

Title
Date
Story (HTML)

The administrator will need to be able to add news items, edit existing items and delete items as well.
As imagined, [...]]]></description>
			<content:encoded><![CDATA[<p>A really common type of PHP script is an add/edit/delete form. This is typically used in a back-end content management system for an administrator to add/edit/delete information. For example, a news editor with three fields:</p>
<ol>
<li>Title</li>
<li>Date</li>
<li>Story (HTML)</li>
</ol>
<p>The administrator will need to be able to add news items, edit existing items and delete items as well.</p>
<p>As imagined, this requires 3 separate form functions:</p>
<ol>
<li>Add Function (title,date,story)</li>
<li>Edit Function (title,date,story)</li>
<li>Delete Function (id)</li>
</ol>
<p>To make this form more efficient and easier for the user, a good coding practice is to join parts of these functions. What we end up with is only two user form pages and integrated functions. The initial page will consist of two separate forms:</p>
<ol>
<li>Add Form with Title Input Box</li>
<li>Edit/Delete Form with Select ID Box</li>
</ol>
<p>The Add form submits to a database insert query and then returns the edit function with the inserted mysql row id. This cuts out the code for making an entire add form and insert code. The Select Box actually only submits to the Edit Button, which the function is self explanatory. Finally, the delete button uses a simple onClick method to append the selected ID onto the URL, by which the page recognizes the GET variable and deletes it. Of course, it&#8217;s good practice to always have a confirm delete function, before passing the URL on.</p>
<p>Tricks like these are easy to implement with simple forms, but efficient coding practices are hard to maintain with larger and more dynamic forms. These types of forms take much more time to ensure the correct usability and efficiency are implemented. Take for example a recent form I did for listing an item on an eBay like site. I&#8217;ve done plenty of real estate listing forms before, but this one would be used by the general public, not just an administrator. It&#8217;s easy to teach an administrator what to do and what not to do, but when coding for the general public, all possibilities must be considered!</p>
<p>A good initial step is to write/think about the usability aspect of the form &#8211; that will save you some time! One of the main issues (small, but still an issue) was denying multiple listing adds from a user. Let&#8217;s say a user wants to create a new listing. With multiple steps (like on eBay), we can&#8217;t just have one big add form, we need to break it up. If we break it up, generally, the first part of the form will add a new row to the database and the remaining parts will update that row. Simple right? Wrong!</p>
<p>The problem here is the ability for users to go back and refresh, which means multiple rows added, which equals a dirty database and a bad user experience. How can we fix that? Well one of the first thoughts was to add a random ID on the initial load of the first part of the form, before anything is added. That ID is added to the database with the first data, and if the back button is pressed, we can check to see if that ID is present. Unfortunately, that solution doesn&#8217;t solve the problem entirely. If the user goes back (too far) to the homepage and returns to the initial part of the form, the random ID is different and so it starts a new row in the database. To really solve this problem, we need to thoroughly understand what is happening here.</p>
<p>Users like to go back and forth between pages, which can sometimes drive a programmer nuts! Users do this to check over or edit the data they&#8217;ve put in, fair enough. What we need is a system that allows them to jump to any page, see data they&#8217;ve put in before, and edit that data. This can get a little tricky when you start including server side error checking, messaging, and splitting the data between the POST data (what they&#8217;ve submitted) and what&#8217;s already in the database, but we won&#8217;t touch on any of that. What we&#8217;re interested in here is allowing the user to jump between pages with their data in there. The answer then is to be filling in forms with information that&#8217;s already in the database. Where then do we add the database row for which they&#8217;ll be using? The answer would be before the form starts! The problem with that though is, again, multiple row adding.</p>
<p>Say the user goes to the add a new listing form, and a row is input into our database with an id returned. Everything is good, the user can jump to any page to update info, except our initial page, because it will add another row. To prevent this from happening, we use an active field in our row, as well as putting the users&#8217; username in there. The active field is defaulted to zero (0) and only is active when the listing is complete (or when the user is done jumping around). When the form starts now, we can then use a session variable to access to the user&#8217;s username and lookup to see if there is a listing by that user with active set to zero. If there is (means they&#8217;ve refreshed/revisited that page), we&#8217;ll use that listing id, and if there isn&#8217;t (they just started the form up) we&#8217;ll create a new row with the username in it and use that listing id. Everything else falls together, and now a form process with step by step links is available to the user to jump around wherever they want without losing any data.</p>
<p>To implement restrictive step links at the top (they can only click on where they&#8217;ve been), you can store what step that listing is on and update it in each subsequent function. Since the user is able to jump around though, you&#8217;ll want to make sure that the step only gets updated if the new value is greater that the current database value.</p>
<p>Overall, efficient code and good usability takes great planning.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/efficient-form-direction-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

