<?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>bgallz.org &#124; Web coding &#38; design tutorials, scripts, resources and more. &#187; Code</title>
	<atom:link href="http://bgallz.org/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://bgallz.org</link>
	<description>Web coding &#38; design tutorials, scripts, resources and more.</description>
	<lastBuildDate>Tue, 10 Jan 2012 00:58:39 +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>Check if Field Exists in Mysql Table</title>
		<link>http://bgallz.org/977/check-field-exists-mysql-table/</link>
		<comments>http://bgallz.org/977/check-field-exists-mysql-table/#comments</comments>
		<pubDate>Tue, 10 May 2011 17:03:42 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[exists]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=977</guid>
		<description><![CDATA[Sometimes it is useful to know if a field exists in a mysql table before running a query using that field name, especially when the field name is coming from some kind of user input.
So to do this we use the function mysql_list_fields to grab the fields out of a table and run through them with a for loop until ...]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is useful to know if a field exists in a mysql table before running a query using that field name, especially when the field name is coming from some kind of user input.</p>
<p>So to do this we use the function <strong>mysql_list_fields</strong> to grab the fields out of a table and run through them with a <em>for loop</em> until we find the one we are looking for &#8211; using the function <strong>mysql_field_name</strong>, in which case we return true. If we don&#8217;t find it, the function returns false.</p>
<pre>
&lt;?php

function fieldExists($table,$field)
{

global $db; // DATABASE NAME
// This function is made to have a mysql connection previously established. You can pass the database name globally like this.

$tableFields = mysql_list_fields($db,$table);

for($i=0;$i&lt;mysql_num_fields($tableFields);$i++){
// Run loop through fields.

if(mysql_field_name($tableFields, $i) == $field){
return true;
// We found the field we were looking for. Return true.
}

}
// No return otherwise, false.

}

?&gt;
</pre>
<p>And it&#8217;s that easy!</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=977&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/977/check-field-exists-mysql-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoid Duplicate Content Pages</title>
		<link>http://bgallz.org/907/avoid-duplicate-content-pages/</link>
		<comments>http://bgallz.org/907/avoid-duplicate-content-pages/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 22:41:29 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[HTML tags]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[pages]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=907</guid>
		<description><![CDATA[Many people do not think about the possibility of duplicate content  pages on their website, when this is very common and easily avoidable.  All it takes is a little HTML in the head tags of the page.
What is a duplicate content page?
Duplicate content is content that is showing up on the Internet by multiple URLs. Another words, a ...]]></description>
			<content:encoded><![CDATA[<p>Many people do not think about the possibility of duplicate content  pages on their website, when this is very common and easily avoidable.  All it takes is a little HTML in the head tags of the page.</p>
<p><span style="text-decoration: underline;"><strong>What is a duplicate content page?</strong></span></p>
<p>Duplicate content is content that is showing up on the Internet by multiple URLs. Another words, a page like <em>aboutus.php</em> might be coming with the same content as <em>aboutus.php?do=send</em>.</p>
<p>This causes some problems with search engines as far as determining  which page the engine should use for query matches, page ranking, use of  meta tags between the two versions, and just which one to include for  their indices.</p>
<p><span style="text-decoration: underline;"><strong>How do you avoid duplicate content?</strong></span></p>
<p>Let&#8217;s say these are your pages that are coming with the same content:</p>
<p><strong>Original source:</strong> <span style="color: blue;"><br />
post.php?id=1</span>.</p>
<p><strong>Duplicate content pages:</strong><br />
<span style="color: blue;">post.php?id=1&amp;lang=en<br />
post.php?id=1&amp;do=login</span></p>
<p>On post.php we can include a &lt;link&gt; tag that will reference to the  original source so Search Engines gather the original correct  information from the server, rather than trying to decide between the  serveral duplicate pages.</p>
<p>Place in the &lt;head&gt; tags of <strong>post.php</strong>:</p>
<pre>
echo&nbsp;&#039;&lt;link&nbsp;href=&quot;./post.php?id=&#039;.((int)$_GET[&#039;id&#039;]).&#039;&quot;&nbsp;rel=&quot;canonical&quot;&nbsp;/&gt;&#039;;
</pre>
<p>This will take the <strong>$id</strong> and put it into the URL as just <strong>post.php?id=$id</strong>.  So any other URL parameters, such as lang=en, or do=login, will not be  read as a duplicate page, but tell search engines to use the content of  just <strong>post.php?id=$id</strong>.</p>
<p>If you do not need to use PHP and you just want the page to load a set content of just <strong>post.php</strong> then you would use the tag like so:</p>
<pre>
&lt;link href=&quot;./post.php&quot; rel=&quot;canonical&quot; /&gt;
</pre>
<p>When using this method, you want to be sure that you are consistent  throughout your website with your canonical URLs. If your canonical url  is like: &#8220;http://www.bgallz.org/&#8221; then you want to use &#8220;www&#8221; in all of  your URL references and tags for the domain.</p>
<p>Now, if you have pages that you do NOT want included in any search  engine queries or crawled by search engine bots, then you want to use a  META tag with &#8220;noindex, nofollow&#8221;.</p>
<p>To block a page from search engine indexes places the following in the &lt;head&gt; tags:</p>
<pre>
<pre>
&lt;meta name=&quot;robots&quot; content=&quot;noindex, nofollow&quot;&gt;
</pre>
<p>Walla!</pre>
<img src="http://bgallz.org/?ak_action=api_record_view&id=907&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/907/avoid-duplicate-content-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Div Float Property</title>
		<link>http://bgallz.org/686/html-div-float-property/</link>
		<comments>http://bgallz.org/686/html-div-float-property/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 19:16:25 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML tags]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=686</guid>
		<description><![CDATA[Using the HTML tag &#8211; &#60;div&#62; and the float style property, you can make designs for your websites. Well, you can make layouts for where design could be. This is a good structural tool in laying out where content will be on your web pages, images, blurbs, etc.
Let&#8217;s say we want a page to look like this:
First I&#8217;m going to ...]]></description>
			<content:encoded><![CDATA[<p>Using the HTML tag &#8211; &lt;div&gt; and the float style property, you can make designs for your websites. Well, you can make layouts for where design could be. This is a good structural tool in laying out where content will be on your web pages, images, blurbs, etc.</p>
<div id="attachment_689" class="wp-caption alignright" style="width: 298px"><a href="http://bgallz.org/wp-content/uploads/2010/11/divfloatlayout1.gif"><img class="size-full wp-image-689" title="divfloatlayout" src="http://bgallz.org/wp-content/uploads/2010/11/divfloatlayout1.gif" alt="Div Float Layout" width="288" height="288" /></a><p class="wp-caption-text">Div Float Layout</p></div>
<p>Let&#8217;s say we want a page to look like this:</p>
<p>First I&#8217;m going to set up the CSS styles we will set our &lt;div&gt;&#8217;s to in the HTML to give this page the right look as far as padding, margins, borders, etc. Once we have all the styles defined we will call them to the DIV tags in our HTML like so: &lt;div class=&#8221;CLASSNAME&#8221;&gt;. Using the right float&#8217;s in the right order will place our DIVs in the right places to make this layout.</p>
<p>This will go in our &lt;head&gt;  tags of the HTML page:</p>
<pre>
html, body, center {
padding: 0px;
margin: 0px;
height: 100%;
}
.header {
padding: 8px;
vertical-align: middle;
height: 80px;
background: #d60000;
}
.banner {
float: left;
border: 0;
vertical-align: middle;
width: 500px;
height: 60px;
}
.ads {
padding: 10px 0px;
float: right;
width: 300px;
height: 60px;
vertical-align: middle;
background: #ffb448;
}
.wrapper { /* Main page holder. */
padding: 10px;
width: 875px;
background: #fff;
height: 100%;
}
.page {
padding: 10px 0px;
width: 630px;
float: left;
height: 100%;
}
.top {
padding: 5px;
height: 40px;
background: #ff7c7c;
margin:0;
}
#boxes {
padding: 5px 0px;
}
.box {
width: 197px;
height: 197px;
padding: 3px;
margin: 3px;
background: #ffddaa;
float: right;
}
.rightside {
float: right;
text-align: center;
height: 100%;
padding: 10px 0px;
}
.nav {
padding: 5px;
background: #ccc;
width: 200px;
height: 100%;
min-height: 600px;
}
.content {
margin: 20px 0px;
width: 600px;
text-align: left;
}
</pre>
<p>Now we have to write the HTML to use these styles appropriately.</p>
<p>Here is our &lt;body&gt; HTML:</p>
<pre>
&lt;body&gt;
&lt;center&gt;
&lt;div class=&quot;wrapper&quot; align=&quot;center&quot;&gt;
&lt;div class=&quot;header&quot;&gt;
&lt;div class=&quot;ads&quot;&gt;Ads Here&lt;/div&gt;
&lt;div class=&quot;banner&quot;&gt;Banner Here&lt;/div&gt;
&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;rightside&quot;&gt;
&lt;div align=&quot;center&quot; class=&quot;nav&quot;&gt;Navigation&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot;&gt;
&lt;div class=&quot;top&quot;&gt;Content Here&lt;/div&gt;
&lt;div id=&quot;boxes&quot;&gt;
&lt;div class=&quot;box&quot; id=&quot;3&quot;&gt;Box 3&lt;/div&gt;
&lt;div class=&quot;box&quot; id=&quot;2&quot;&gt;Box 2&lt;/div&gt;
&lt;div class=&quot;box&quot; id=&quot;1&quot;&gt;Box 1&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;p&gt;Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here!Content Here, lots and lots of content here!&lt;/p&gt;
&lt;p&gt;Content Here, lots and lots of content here!Content Here, lots and lots of content here!Content Here, lots and lots of content here!Content Here, lots and lots of content here!Content Here, lots and lots of content here!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/center&gt;
&lt;/body&gt;
</pre>
<p><a title="Div Float Layout" href="http://bgallz.org/html/divfloat.html" target="_blank">Take a look at the HTML in action here!</a></p>
<p>If you notice in the HTML the box&#8217;s are placed in descending order inside the &#8220;boxes&#8221; div ID. Since the box class is set to to the right:</p>
<pre>
.box {
float: right;
}
</pre>
<p>We put the boxes in descending order so that the HTML will read down the page and float the first one to the right, then the next, then the last. So it floats BOX3, then BOX2, then BOX1.</p>
<p>Using the float style property of DIV tags is really useful in making layouts because it does not require any real guidelines to follow as far as where it is on the page. This sounds a little wordy but basically with a combination of float, and position style attributes you can make your DIV&#8217;s go where ever you want.</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=686&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/686/html-div-float-property/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP fopen() Function</title>
		<link>http://bgallz.org/649/php-fopen-function/</link>
		<comments>http://bgallz.org/649/php-fopen-function/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 13:31:06 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[fopen]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=649</guid>
		<description><![CDATA[The fopen() function will open any valid file or url.
If the function fails it will return false along with an error generated. You can hide the error message by adding an &#8220;@&#8221; in front of the function name.
Syntax

fopen(filename, mode, include_path, context);

Parameters
filename (String &#124; Required)
This specifies the URL or file to open. Example: &#8220;./files/myfile.zip&#8220;.
mode (String &#124; Required)
The type of access you ...]]></description>
			<content:encoded><![CDATA[<p>The fopen() function will open any valid file or url.</p>
<p>If the function fails it will return false along with an error generated. You can hide the error message by adding an &#8220;@&#8221; in front of the function name.</p>
<h1>Syntax</h1>
<pre>
fopen(filename, mode, include_path, context);
</pre>
<h1>Parameters</h1>
<p><span style="text-decoration: underline;"><em>filename</em></span> (String | Required)</p>
<p>This specifies the URL or file to open. Example: &#8220;<em>./files/myfile.zip</em>&#8220;.</p>
<p><span style="text-decoration: underline;"><em>mode</em></span> (String | Required)</p>
<p>The type of access you are requesting for the file.</p>
<p>These are the valid access modes:</p>
<li>&#8220;<strong>r</strong>&#8221; (Read only. Starts at the beginning of the file)</li>
<li>&#8220;<strong>r+</strong>&#8221; (Read/Write. Starts at the beginning of the file)</li>
<li>&#8220;<strong>w</strong>&#8221; (Write only. Opens and clears the contents of file; or creates a new file if it doesn&#8217;t exist)</li>
<li>&#8220;<strong>w+</strong>&#8221; (Read/Write. Opens and clears the contents of file; or creates a new file if it doesn&#8217;t exist)</li>
<li>&#8220;<strong>a</strong>&#8221; (Write only. Opens and writes to the end of the file or creates a new file if it doesn&#8217;t exist)</li>
<li>&#8220;<strong>a+</strong>&#8221; (Read/Write. Preserves file content by writing to the end of the file)</li>
<li>&#8220;<strong>x</strong>&#8221; (Write only. Creates a new file. Returns FALSE and an error if file already exists)</li>
<li>&#8220;<strong>x+</strong>&#8221; (Read/Write. Creates a new file. Returns FALSE and an error if file already exists)</li>
<p><em><span style="text-decoration: underline;">include_path</span></em> (Boolean | Optional)</p>
<p>This can be set to 1 or TRUE if you want to search for the requested file in the include path, also.</p>
<p><em><span style="text-decoration: underline;">context</span></em> (String | Optional)</p>
<p>Defines the context of the file stream. This is a set of options that change the behavior of the stream.</p>
<p>Originally posted at <a href="http://www.w3schools.com/php/func_filesystem_fopen.asp" target="_self">w3schools.com</a>:</p>
<blockquote><p><em><strong>Note:</strong> When writing to a text file, be sure to use the correct line-ending character! Unix systems use \n, Windows systems use \r\n, and Macintosh systems use \r as the line ending character. Windows offers a translation flag (&#8216;t&#8217;) which will translate \n to \r\n when working with the file. You can also use &#8216;b&#8217; to force binary mode. To use these flags, specify either &#8216;b&#8217; or &#8216;t&#8217; as the last character of the mode parameter.</em></p></blockquote>
<p><a href="http://bgallz.org/62/php-upload-file-from-url/" target="_self">Here</a> I showed you how to upload a file from a URL using this function.</p>
<p>Example:</p>
<pre>
$filename = "./images/myimage.jpg";

$file = fopen($filename,"r");

if($file){
echo "We have the file.";
} else {
echo "File not found.";
}
</pre>
<img src="http://bgallz.org/?ak_action=api_record_view&id=649&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/649/php-fopen-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Pagination with Mysql</title>
		<link>http://bgallz.org/556/php-pagination-mysql/</link>
		<comments>http://bgallz.org/556/php-pagination-mysql/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 16:52:26 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=556</guid>
		<description><![CDATA[So you have a Mysql table you want to pull data from, but you don&#8217;t want to flood the page with everything in the table right! So you need some pagination to seperate all the content in the table into easy to open pages.
So let&#8217;s say this is your mysql query:

$sql = mysql_query("SELECT * FROM table1") or die(mysql_error());

So this will ...]]></description>
			<content:encoded><![CDATA[<p>So you have a Mysql table you want to pull data from, but you don&#8217;t want to flood the page with everything in the table right! So you need some pagination to seperate all the content in the table into easy to open pages.</p>
<p><strong>So let&#8217;s say this is your mysql query:</strong></p>
<pre>
$sql = mysql_query("SELECT * FROM table1") or die(mysql_error());
</pre>
<p>So this will grab everything from <em>table1</em>.</p>
<p>If we have a lot of rows in this table this is going to return all of them, so we need to make a pagination for all the rows returned. This requires modifying the query and adding some variables. I like to have the <em>PER_PAGE</em>,<em>OFFSET</em>, and <em>PAGE_NUM</em> variables defined so you can use them globally in every class and function, however you may not want the same values throughout so declare them as you wish.</p>
<p><strong>Here is the header PHP for definitions:</strong></p>
<pre>
// === START Pagination definitions === //
$pgNperPage=15;
$pgNpageNum=1;
if(isset($_GET["p"])){
$pgNpageNum=(int)$_GET["p"];
}
$pgNoffset = ($pgNpageNum - 1) * $pgNperPage;
// definitions
define("SITE_URL","http://mysite.com/",true);
define("PER_PAGE",$pgNperPage,true);
define("OFFSET",$pgNoffset,true);
define("PAGE_NUM",$pgNpageNum,true);
// === END Pagination definitions === //
</pre>
<p>So we have to modify the query we use in <em>$sql</em> to include a limit with the offset and per page values used. I have made a pagination function which will do everything for me. We&#8217;ll pass the query along with some parameters through this function to output the new query and the pagination HTML.</p>
<p><strong>Here is the function syntax:</strong></p>
<pre>
pagination($query,$pageNum,$perpage,$sortable,$cat="",$sort="",$headers="",$pageL="");
</pre>
<p><span style="text-decoration: underline;"><strong>Function Paremeters:</strong></span></p>
<ul>
<li><span style="text-decoration: underline;">$query</span> &#8211; The original query to use for the Mysql. i.e. &#8220;SELECT * FROM table1&#8243;. (No ORDER BY or LIMIT).</li>
<li><span style="text-decoration: underline;">$pageNum</span> &#8211; Current page number.</li>
<li><span style="text-decoration: underline;">$perpage</span> &#8211; Per page integer value.</li>
<li><span style="text-decoration: underline;">$sortable</span> &#8211; Array of sortable fields in mysql table to order the results by.</li>
<li><span style="text-decoration: underline;">$cat</span> &#8211; What is being paginated. i.e. (Users, videos, comments, etc.) [<span style="color: #ff0000;">Optional</span>]</li>
<li><span style="text-decoration: underline;">$sort</span> &#8211; Field in Mysql table to sort it by. Default in the function definition is &#8220;timestamp&#8221; &#8211; usually used for date. [<span style="color: #ff0000;">Optional</span>]</li>
<li><span style="text-decoration: underline;">$headers</span> &#8211; Additional URL headers besides the sort and page number. i.e. &#8220;&amp;g=bf-2142&#8243; (Start with <span style="color: #008000;"><strong>&amp;</strong></span> not <span style="color: #800000;"><del>?</del></span>) [<span style="color: #ff0000;">Optional</span>]</li>
<li><span style="text-decoration: underline;">$pageL</span> &#8211; Pagination letter. Useful if you have multiple paginations on one page. i.e. &#8220;cp&#8221;. (Default is p.) [<span style="color: #ff0000;">Optional</span>]</li>
</ul>
<p><strong>Here is the pagination function definition:<br />
</strong></p>
<pre>
function pagination($query,$pageNum,$perpage,$sortable,$cat="",$sort="",$headers="",$pageL=""){
$pagination = array();
$paginationDetails = "";
$adjacents = 3;
if(!$perpage){
$perpage = 15; // default
}
if($cat){
$cat = " ".$cat."";
}
$pageNum = (int)$pageNum;
if(!$pageNum){
$pageNum=1;
}
if(!$pageL){
$pageL="p";
}
$pgNoffset = ($pageNum - 1) * $perpage;

if(isset($_GET['dsc']) &amp;&amp; $_GET['dsc'] != ""){
$dsc = "DESC";
$urldsc = "&amp;dsc=1";
} else {
$dsc = "";
$urldsc = "";
}
if(is_array($sortable)){
if(in_array($sort,$sortable)){
$sort = trim($sort);
} else {
$sort = "";
}
}
if($sort){
$order_by = "ORDER BY ".$sort." ".$dsc."";
} else {
$order_by = "";
}
$limit = "LIMIT ".$pgNoffset.",".$perpage."";
$queryNew = $query.' '.$order_by.' '.$limit;
$pagination[] = $queryNew;
if(strpos($_SERVER["REQUEST_URI"],"?")){
$pos = strpos($_SERVER["REQUEST_URI"],"?");
} else {
$pos = strlen($_SERVER["REQUEST_URI"]);
}
$pageURL = substr($_SERVER["REQUEST_URI"],0,$pos);

$pageURL .= "?sort=".$sort."";
$pageURL .= "&amp;dsc=".$dsc."";
$pageURL .= $headers;

$sql = mysql_query($queryNew) or die(mysql_error());
$count = mysql_num_rows($sql);
if($count &gt; 0){
$totalQuery = mysql_query($query) or die(mysql_error());
$totalCount = mysql_num_rows($totalQuery);
$total = ceil($totalCount / $perpage);
$pm1 = $total - 1;
$paginationDetails .= '&lt;p&gt;
&lt;table width="100%" align="center" border="0" cellpadding="2" cellspacing="1"&gt;&lt;tr&gt;
&lt;td align="left"&gt;&lt;div&gt;Displaying '.$count.' of '.$totalCount.$cat.'.&lt;/div&gt;&lt;/td&gt;
&lt;td align="right"&gt;
&lt;table border="0" align="right" cellpadding="2" cellspacing="1" width="100%"&gt;&lt;tr&gt;
&lt;td&gt;Page '.$pageNum.' of '.$total.'&lt;/td&gt;';
if($pageNum &gt; 1){
// previous button
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.(PAGE_NUM - 1).'"&gt;&amp;lsaquo; Prev&lt;/a&gt;&lt;/td&gt;';
}
// conditionals for breaking up the pages
if($total &lt; 7 + ($adjacents*2)){
// not enought to break up
for($page=1;$page&lt;=$total;$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
}
else if($total &gt; 5 + ($adjacents*2)){
// enought to hide some
if($pageNum &lt; 1 + ($adjacents*2)){
// hide later pages
for($page=1;$page&lt;5+($adjacents*2);$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$pm1.'"&gt;'.$pm1.'&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$total.'"&gt;'.$total.'&lt;/a&gt;&lt;/td&gt;';
}
else if($total - ($adjacents*2) &gt; $pageNum &amp;&amp; $pageNum &gt; ($adjacents * 2)){
// in middle, hide little front and back
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=1"&gt;1&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=2"&gt;2&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
for($page=($pageNum - $adjacents);$page&lt;=($pageNum + $adjacents);$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$page.'&amp;'.$pageL.'='.$pm1.'"&gt;'.$pm1.'&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$page.'&amp;'.$pageL.'='.$total.'"&gt;'.$total.'&lt;/a&gt;&lt;/td&gt;';
}
else {
// close to end, hide early pages
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=1"&gt;1&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=2"&gt;2&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
for($page=$total - (3 +($adjacents*2));$page&lt;=$total;$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
}
}

if($pageNum &lt; $total){
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.($pageNum + 1).'"&gt;Next &amp;rsaquo;&lt;/a&gt;&lt;/td&gt;';
}
$paginationDetails .= '&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;';
$pagination[] = $paginationDetails;
}
return $pagination;
}
</pre>
<p>Now we just need to include the HTML and CSS classes for the pagination so viewers can navigate through the pages returned from this query.</p>
<p><strong>Pagination CSS:</strong></p>
<pre>
&lt;!--
.pagination {
margin: 0px;
background-color: #eaeaea;
padding: 0px;
}
.a_page {
margin: 0px;
padding: 2px;
color: #343434;
background-color: #f5f5f5;
font-size: 11px;
font-family: tahoma;
}
.a_page a {
color: #000;
text-decoration: underline;
}
.page_selected {
background-color: #ffffff;
color: #000;
font-weight: bold;
padding: 1px;
border: 1px solid #d9dbdc;
font-size: 11px;
font-family: tahoma;
}
.page_selected a {
color: #000;
}
--&gt;.pagination,.pagination div {
background-color: #eee;
font: 11px tahoma;
border: 1px solid #ccc;
text-align: left;
}
.a_td {
color: #343434;
background-color: #fff;
font-size: 11px;
font-family: tahoma;
}
.a_page {
color: #343434;
background-color: #fff;
font-size: 11px;
font-family: tahoma;
padding:0px;
}
.a_page:hover {
background-color: #eee;
}
.a_page a {
display:block;
padding:2px;
color: #333;
text-decoration: none;
}
.page_selected {
background-color: #333;
color: #fff;
font-weight: bold;
font-size: 11px;
font-family: tahoma;
}
.page_selected a {
color: #000;
}
</pre>
<p>Now we have the function included on our page along with the necessary CSS styles. Now we can call the function and echo the contents of the returned array. The function <strong>pagination</strong> returns an array like so: <em>pagination = [newMysqlQuery, paginationHTML]</em>.<strong></strong></p>
<p><strong>So let&#8217;s say this was our function for downloads:<br />
</strong></p>
<pre>
function downloads($g){
$g=mysql_real_escape_string($g); // Game
$validSorts = array("title","catType","dl_count","timestamp"); // Sorts
if(isset($_GET['sort']) &amp;&amp; in_array($_GET['sort'],$validSorts)){
$sort = mysql_real_escape_string($_GET['sort']);
} else {
$sort = 'timestamp'; // default sort used.
}
if(isset($_GET['dsc'])){
$desc = "DESC";
} else {
$desc = "";
}
if(isset($_GET['p'])){
$page = (int)$_GET['p'];
} else {
$page = 1;
}
$query = "SELECT * FROM downloads WHERE gameCat = '$g'";
$pagination = pagination($query,$page,15,$validSorts,"downloads",$sort,"&amp;g=".$g.""); // Call the function.
$sql = mysql_query($pagination[0]) or die(mysql_error()); // $pagination[0] = new query.
$count = mysql_num_rows($sql);
}
</pre>
<p>Now we have called the pagination function with some variables for displaying our downloads. Along with printing the pagination HTML you could display the rows with the new Mysql query that the function returns.</p>
<p><a title="Display Mysql Rows from Table" href="http://bgallz.org/82/mysql-rows-from-a-table/">See how to display Mysql Rows here!</a></p>
<p><strong>For this example we will simply echo the pagination HTML:</strong></p>
<pre>
echo $pagination[1];
</pre>
<p><strong>Check this function out LIVE here:</strong></p>
<p><a title="Members" href="http://bfgamerz.com/members.php">http://bfgamerz.com/members.php</a></p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=556&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/556/php-pagination-mysql/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>PHP Date() Function</title>
		<link>http://bgallz.org/549/php-date-function/</link>
		<comments>http://bgallz.org/549/php-date-function/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 22:55:57 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=549</guid>
		<description><![CDATA[The date() function converts a given timestamp into a readable date format.
Here is the syntax for this function:
Syntax

date(format,timestamp);

Parameters:
format
This parameter determines the format and how the date will read.
For example: &#8220;Saturday, Nov. 16th 2009&#8221; would be the following code:

$timestamp = time();
date("l, M. jS Y",$timestamp);

timestamp
This parameter is the timestamp you want to use to format a date from. This timestamp is a ...]]></description>
			<content:encoded><![CDATA[<p>The date() function converts a given <em>timestamp</em> into a readable date format.</p>
<p>Here is the syntax for this function:</p>
<h1>Syntax</h1>
<pre>
date(format,timestamp);
</pre>
<h1>Parameters:</h1>
<p><span style="text-decoration: underline;"><em>format</em></span><br />
This parameter determines the format and how the date will read.</p>
<p>For example: &#8220;<strong>Saturday, Nov. 16th 2009</strong>&#8221; would be the following code:</p>
<pre>
$timestamp = time();
date("l, M. jS Y",$timestamp);
</pre>
<p><span style="text-decoration: underline;"><em>timestamp</em></span><br />
This parameter is the timestamp you want to use to format a date from. This <em>timestamp</em> is a number of seconds since a certain date, since we used the current <em>timestamp</em> of <em>time()</em> we are making the date for the current time.</p>
<p>We&#8217;ll break down our example to see what each set of letters represents as part of the date&#8217;s format.</p>
<ul>
<li><strong>l</strong> &#8211; day of the week, textual, long; i.e. ‘Friday’</li>
<li><strong>M</strong> &#8211; month, textual, 3 letters; i.e. ‘Jan’</li>
<li><strong>j</strong> &#8211; day of the month without leading zeros; i.e. ’1′ to ’31′</li>
<li><strong>S</strong> &#8211; English ordinal suffix, textual, 2 characters; i.e. ‘th’,‘nd’</li>
<li><strong>Y</strong> &#8211; year, 4 digits; i.e. ’1999′</li>
</ul>
<p><a title="PHP date Format Reference" href="http://bgallz.org/533/php-date-formats-reference/" target="_self">View the complete date format reference here.</a></p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=549&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/549/php-date-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Date Formats Reference</title>
		<link>http://bgallz.org/533/php-date-formats-reference/</link>
		<comments>http://bgallz.org/533/php-date-formats-reference/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 04:38:13 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=533</guid>
		<description><![CDATA[Here is a table for formatting the PHP function date() and the letters used to represent different parts of a timestamp.



a
&#8216;am&#8217; or &#8216;pm&#8217;


A
&#8216;AM&#8217; or &#8216;PM&#8217;


B
Swatch Internet time


d
day of the month, 2 digits with leading zeros; i.e. &#8217;01&#8242; to
&#8217;31&#8242;


D
day of the week, textual, 3 letters; i.e. &#8216;Fri&#8217;


F
month, textual, long; i.e. &#8216;January&#8217;


g
hour, 12-hour format without leading zeros; i.e. &#8217;1&#8242; to &#8217;12&#8242;


G
hour, 24-hour ...]]></description>
			<content:encoded><![CDATA[<p>Here is a table for formatting the PHP function <em>date()</em> and the letters used to represent different parts of a timestamp.</p>
<table class="post_table" border="0" cellspacing="1" cellpadding="3" width="100%">
<tbody>
<tr>
<td width="104">a</td>
<td class="data" width="100%">&#8216;am&#8217; or &#8216;pm&#8217;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">A</td>
<td class="data" width="100%">&#8216;AM&#8217; or &#8216;PM&#8217;</td>
</tr>
<tr>
<td width="104">B</td>
<td class="data" width="100%">Swatch Internet time</td>
</tr>
<tr bgcolor="#eee">
<td width="104">d</td>
<td class="data" width="100%">day of the month, 2 digits with leading zeros; i.e. &#8217;01&#8242; to<br />
&#8217;31&#8242;</td>
</tr>
<tr>
<td width="104">D</td>
<td class="data" width="100%">day of the week, textual, 3 letters; i.e. &#8216;Fri&#8217;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">F</td>
<td class="data" width="100%">month, textual, long; i.e. &#8216;January&#8217;</td>
</tr>
<tr>
<td width="104">g</td>
<td class="data" width="100%">hour, 12-hour format without leading zeros; i.e. &#8217;1&#8242; to &#8217;12&#8242;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">G</td>
<td class="data" width="100%">hour, 24-hour format without leading zeros; i.e. &#8217;0&#8242; to &#8217;23&#8242;</td>
</tr>
<tr>
<td width="104">h</td>
<td class="data" width="100%">hour, 12-hour format; i.e. &#8217;01&#8242; to &#8217;12&#8242;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">H</td>
<td class="data" width="100%">hour, 24-hour format; i.e. &#8217;00&#8242; to &#8217;23&#8242;</td>
</tr>
<tr>
<td width="104">i</td>
<td class="data" width="100%">minutes; i.e. &#8217;00&#8242; to &#8217;59&#8242;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">I (capital i)</td>
<td class="data" width="100%">&#8217;1&#8242; if Daylight Savings Time, &#8217;0&#8242; otherwise.</td>
</tr>
<tr>
<td width="104">j</td>
<td class="data" width="100%">day of the month without leading zeros; i.e. &#8217;1&#8242; to &#8217;31&#8242;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">l (lowercase &#8216;L&#8217;)</td>
<td class="data" width="100%">day of the week, textual, long; i.e. &#8216;Friday&#8217;</td>
</tr>
<tr>
<td width="104">L</td>
<td class="data" width="100%">boolean for whether it is a leap year; i.e. &#8217;0&#8242; or &#8217;1&#8242;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">m</td>
<td class="data" width="100%">month; i.e. &#8217;01&#8242; to &#8217;12&#8242;</td>
</tr>
<tr>
<td width="104">M</td>
<td class="data" width="100%">month, textual, 3 letters; i.e. &#8216;Jan&#8217;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">n</td>
<td class="data" width="100%">month without leading zeros; i.e. &#8217;1&#8242; to &#8217;12&#8242;</td>
</tr>
<tr>
<td width="104">r</td>
<td class="data" width="100%">RFC 822 formatted date; i.e. &#8216;Thu, 21 Dec 2000 16:01:07 +0200&#8242;<br />
(added in PHP 4.0.4)</td>
</tr>
<tr bgcolor="#eee">
<td width="104">s</td>
<td class="data" width="100%">seconds; i.e. &#8217;00&#8242; to &#8217;59&#8242;</td>
</tr>
<tr>
<td width="104">S</td>
<td class="data" width="100%">English ordinal suffix, textual, 2 characters; i.e. &#8216;th&#8217;,<br />
&#8216;nd&#8217;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">t</td>
<td class="data" width="100%">number of days in the given month; i.e. &#8217;28&#8242; to &#8217;31&#8242;</td>
</tr>
<tr>
<td width="104">T</td>
<td class="data" width="100%">Timezone setting of this machine; i.e. &#8216;MDT&#8217;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">U</td>
<td class="data" width="100%">seconds since the epoch</td>
</tr>
<tr>
<td width="104">w</td>
<td class="data" width="100%">day of the week, numeric, i.e. &#8217;0&#8242; (Sunday) to &#8217;6&#8242; (Saturday)</td>
</tr>
<tr bgcolor="#eee">
<td width="104">Y</td>
<td class="data" width="100%">year, 4 digits; i.e. &#8217;1999&#8242;</td>
</tr>
<tr>
<td width="104">y</td>
<td class="data" width="100%">year, 2 digits; i.e. &#8217;99&#8242;</td>
</tr>
<tr bgcolor="#eee">
<td width="104">z</td>
<td class="data" width="100%">day of the year; i.e. &#8217;0&#8242; to &#8217;365&#8242;</td>
</tr>
<tr>
<td width="104">Z</td>
<td class="data" width="100%">timezone offset in seconds (i.e. &#8216;-43200&#8242; to &#8217;43200&#8242;). The<br />
offset for timezones west of UTC is always negative, and for those east<br />
of UTC is always positive.</td>
</tr>
</tbody>
</table>
<img src="http://bgallz.org/?ak_action=api_record_view&id=533&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/533/php-date-formats-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Upload and Resize Image</title>
		<link>http://bgallz.org/502/php-upload-resize-image/</link>
		<comments>http://bgallz.org/502/php-upload-resize-image/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:21:42 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=502</guid>
		<description><![CDATA[Many times when you upload a image somewhere you want to resize it to different dimensions based off of a maximum width or height. Here is a simple script that does this for you, using a HTML form and a PHP script. We start with the PHP script that will run if our $_GET['do'] is set to &#8220;upload.&#8221; Then we ...]]></description>
			<content:encoded><![CDATA[<p>Many times when you upload a image somewhere you want to resize it to different dimensions based off of a maximum width or height. Here is a simple script that does this for you, using a HTML form and a PHP script. We start with the PHP script that will run if our <em>$_GET['do']</em> is set to &#8220;upload.&#8221; Then we include the HTML form that has three inputs (max width, max height, image file).</p>
<p><a title="Upload and Resize Demo" href="http://bgallz.org/scripts/upload-resize-image/" target="_blank"><strong>Use the Upload and Resize Demo Here!</strong></a></p>
<p><a href="http://bgallz.org/scripts/upload-resize-image/bgallz.org-Upload-and-Resize-Image-Script.rar"><strong>Download This Script!</strong></a></p>
<p>Here is the PHP:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Upload and Resize PHP Code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="co1">// index.php</span>
<span class="kw2">function</span> generate_resized_image<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$max_dimension</span> <span class="sy0">=</span> <span class="nu0">800</span><span class="sy0">;</span> <span class="co1">// Max new width or height, can not exceed this value.</span>
<span class="re0">$dir</span> <span class="sy0">=</span> <span class="st0">&quot;./images/&quot;</span><span class="sy0">;</span> <span class="co1">// Directory to save resized image. (Include a trailing slash - /)</span>
<span class="co1">// Collect the post variables.</span>
<span class="re0">$postvars</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
<span class="st0">&quot;image&quot;</span>    <span class="sy0">=&gt;</span> <a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">,</span>
<span class="st0">&quot;image_tmp&quot;</span>    <span class="sy0">=&gt;</span> <span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;tmp_name&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_size&quot;</span>    <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;size&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_max_width&quot;</span>    <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_max_height&quot;</span>   <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span>
<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Array of valid extensions.</span>
<span class="re0">$valid_exts</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&quot;jpg&quot;</span><span class="sy0">,</span><span class="st0">&quot;jpeg&quot;</span><span class="sy0">,</span><span class="st0">&quot;gif&quot;</span><span class="sy0">,</span><span class="st0">&quot;png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Select the extension from the file.</span>
<span class="re0">$ext</span> <span class="sy0">=</span> <a href="http://www.php.net/end"><span class="kw3">end</span></a><span class="br0">&#40;</span><a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="sy0">,</span><a href="http://www.php.net/strtolower"><span class="kw3">strtolower</span></a><span class="br0">&#40;</span><a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Check not larger than 175kb.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_size&quot;</span><span class="br0">&#93;</span> <span class="sy0">&lt;=</span> <span class="nu0">179200</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">// Check is valid extension.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span><span class="re0">$ext</span><span class="sy0">,</span><span class="re0">$valid_exts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;jpg&quot;</span> <span class="sy0">||</span> <span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;jpeg&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefromjpeg"><span class="kw3">imagecreatefromjpeg</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;gif&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefromgif"><span class="kw3">imagecreatefromgif</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;png&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefrompng"><span class="kw3">imagecreatefrompng</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="co1">// Grab the width and height of the image.</span>
<a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span><span class="sy0">,</span><span class="re0">$height</span><span class="br0">&#41;</span> <span class="sy0">=</span> <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// If the max width input is greater than max height we base the new image off of that, otherwise we</span>
<span class="co1">// use the max height input.</span>
<span class="co1">// We get the other dimension by multiplying the quotient of the new width or height divided by</span>
<span class="co1">// the old width or height.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="re0">$max_dimension</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="re0">$max_dimension</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="re0">$newwidth</span> <span class="sy0">/</span> <span class="re0">$width</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="re0">$height</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="re0">$max_dimension</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="re0">$max_dimension</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="re0">$newheight</span> <span class="sy0">/</span> <span class="re0">$height</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="re0">$width</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="co1">// Create temporary image file.</span>
<span class="re0">$tmp</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatetruecolor"><span class="kw3">imagecreatetruecolor</span></a><span class="br0">&#40;</span><span class="re0">$newwidth</span><span class="sy0">,</span><span class="re0">$newheight</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Copy the image to one with the new width and height.</span>
<a href="http://www.php.net/imagecopyresampled"><span class="kw3">imagecopyresampled</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="sy0">,</span><span class="re0">$image</span><span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span><span class="re0">$newwidth</span><span class="sy0">,</span><span class="re0">$newheight</span><span class="sy0">,</span><span class="re0">$width</span><span class="sy0">,</span><span class="re0">$height</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Create random 4 digit number for filename.</span>
<span class="re0">$rand</span> <span class="sy0">=</span> <a href="http://www.php.net/rand"><span class="kw3">rand</span></a><span class="br0">&#40;</span>1000<span class="sy0">,</span>9999<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$filename</span> <span class="sy0">=</span> <span class="re0">$dir</span><span class="sy0">.</span><span class="re0">$rand</span><span class="sy0">.</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="co1">// Create image file with 100% quality.</span>
<a href="http://www.php.net/imagejpeg"><span class="kw3">imagejpeg</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="sy0">,</span><span class="re0">$filename</span><span class="sy0">,</span>100<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">return</span> <span class="st0">&quot;&lt;strong&gt;Image Preview:&lt;/strong&gt;&lt;br/&gt;
&lt;img src=<span class="es1">\&quot;</span>&quot;</span><span class="sy0">.</span><span class="re0">$filename</span><span class="sy0">.</span><span class="st0">&quot;<span class="es1">\&quot;</span> border=<span class="es1">\&quot;</span>0<span class="es1">\&quot;</span> title=<span class="es1">\&quot;</span>Resized  Image Preview<span class="es1">\&quot;</span> style=<span class="es1">\&quot;</span>padding: 4px 0px 4px 0px;background-color:#e0e0e0<span class="es1">\&quot;</span> /&gt;&lt;br/&gt;
Resized image successfully generated. &lt;a href=<span class="es1">\&quot;</span>&quot;</span><span class="sy0">.</span><span class="re0">$filename</span><span class="sy0">.</span><span class="st0">&quot;<span class="es1">\&quot;</span> target=<span class="es1">\&quot;</span>_blank<span class="es1">\&quot;</span> name=<span class="es1">\&quot;</span>Download your resized image now!<span class="es1">\&quot;</span>&gt;Click here to download your image.&lt;/a&gt;&quot;</span><span class="sy0">;</span>
<a href="http://www.php.net/imagedestroy"><span class="kw3">imagedestroy</span></a><span class="br0">&#40;</span><span class="re0">$image</span><span class="br0">&#41;</span><span class="sy0">;</span>
<a href="http://www.php.net/imagedestroy"><span class="kw3">imagedestroy</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;File size too large. Max allowed file size is 175kb.&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;Invalid file type. You must upload an image file. (jpg, jpeg, gif, png).&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&quot;do&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&quot;do&quot;</span><span class="br0">&#93;</span> <span class="sy0">==</span> <span class="st0">&quot;upload&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$upload_and_resize</span> <span class="sy0">=</span> generate_resized_image<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$upload_and_resize</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$upload_and_resize</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>
<p>Here is the HTML:</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">HTML Form</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/form.html"><span class="kw2">form</span></a> <span class="kw3">action</span><span class="sy0">=</span><span class="st0">&quot;./index.php?do=upload&quot;</span> <span class="kw3">method</span><span class="sy0">=</span><span class="st0">&quot;post&quot;</span> <span class="kw3">enctype</span><span class="sy0">=</span><span class="st0">&quot;multipart/form-data&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/table.html"><span class="kw2">table</span></a> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;100%&quot;</span> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;center&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">cellpadding</span><span class="sy0">=</span><span class="st0">&quot;2&quot;</span> <span class="kw3">cellspacing</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;100&quot;</span>&gt;</span>
Max Width:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image_max_width&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width: 120px&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">maxlength</span><span class="sy0">=</span><span class="st0">&quot;4&quot;</span> <span class="sy0">/</span>&gt;</span> px.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;</span>
Max Height:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image_max_height&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width: 120px&quot;</span> <span class="kw3">maxlength</span><span class="sy0">=</span><span class="st0">&quot;4&quot;</span> <span class="sy0">/</span>&gt;</span> px.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;</span>
Image:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;file&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image&quot;</span> <span class="kw3">size</span><span class="sy0">=</span><span class="st0">&quot;40&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span> <span class="kw3">colspan</span><span class="sy0">=</span><span class="st0">&quot;2&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/ol.html"><span class="kw2">ol</span></a> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;margin:0;padding:3px 0px 3px 15px&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Max file size: 175 KB.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Allowed extensions: jpg, jpeg, gif, png.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Max Dimension: <span class="sc2">&lt;<a href="http://december.com/html/4/element/em.html"><span class="kw2">em</span></a>&gt;</span>800<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/em.html"><span class="kw2">em</span></a>&gt;</span>px.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ol.html"><span class="kw2">ol</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span> <span class="kw3">colspan</span><span class="sy0">=</span><span class="st0">&quot;2&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Submit!&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;font: 14pt verdana&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/table.html"><span class="kw2">table</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/form.html"><span class="kw2">form</span></a>&gt;</span></pre></div></div>
<p><strong>This will create a form that looks like this:</strong></p>
<p><a name="form"></a></p>
<form action="#form" enctype="multipart/form-data" method="post">
<table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">
<tbody>
<tr>
<td width="100" align="left">Max Width:</td>
<td align="left">
<input style="width: 120px;" maxlength="4" name="image_max_width" type="text" /> px.</td>
</tr>
<tr>
<td align="left">Max Height:</td>
<td align="left">
<input style="width: 120px;" maxlength="4" name="image_max_height" type="text" /> px.</td>
</tr>
<tr>
<td align="left">Image:</td>
<td align="left">
<input name="image" size="40" type="file" /></td>
</tr>
<tr>
<td colspan="2" align="left">
<ol style="margin: 0; padding: 3px 0px 3px 15px;">
<li>Max file size: 175 KB</li>
<li>Allowed extensions: jpg, jpeg, gif, png.</li>
<li>Max Dimension: <em>800</em>px.</li>
</ol>
</td>
</tr>
<tr>
<td align="left colspa=">
<input style="font: 14pt verdana;" name="submit" type="submit" value="Submit!" /></td>
</tr>
</tbody>
</table>
</form>
<p>Then we just have to call the functions returned value (<em>$upload_and_resize</em>).</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Show Upload and Resize</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;upload&quot;&gt;
<span class="kw2">&lt;?php</span> <span class="kw1">echo</span> <span class="re0">$upload_and_resize</span><span class="sy0">;</span> <span class="sy1">?&gt;</span>
&lt;/div&gt;</pre></div></div>
<input id="gwProxy" type="hidden" />
<p><!--Session data--></p>
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<img src="http://bgallz.org/?ak_action=api_record_view&id=502&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/502/php-upload-resize-image/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>PHP Ordinalize Numbers – Add Suffix</title>
		<link>http://bgallz.org/481/php-ordinalize-numbers-add-suffix/</link>
		<comments>http://bgallz.org/481/php-ordinalize-numbers-add-suffix/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 22:23:29 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[numbers]]></category>
		<category><![CDATA[ordinalize]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=481</guid>
		<description><![CDATA[Here is a very simple function to use to ordinalize numbers in PHP. This adds the place value suffix to numbers. So you can turn numbers like 1, 2, 3 into 1st, 2nd, 3rd.
Here is the code:

function ordinalize($int){
if(in_array(($int % 100),range(11,13))){
return $int . "th";
} else {
switch(($int % 10)){
case 1:
return $int . "st";
break;
case 2:
return $int . "nd";
break;
case 3:
return $int . "rd";
break;
default:
return $int ...]]></description>
			<content:encoded><![CDATA[<p>Here is a very simple function to use to ordinalize numbers in PHP. This adds the place value suffix to numbers. So you can turn numbers like 1, 2, 3 into 1st, 2nd, 3rd.</p>
<p>Here is the code:</p>
<pre>
function ordinalize($int){
if(in_array(($int % 100),range(11,13))){
return $int . "th";
} else {
switch(($int % 10)){
case 1:
return $int . "st";
break;
case 2:
return $int . "nd";
break;
case 3:
return $int . "rd";
break;
default:
return $int . "th";
break;
}
}
}
</pre>
<p>Basically the function first checks if the number is in the range of 11-13, and if so it returns the number with &#8220;th&#8221; attached (11th, 12th, 13th). If it is not in this range it checks the remainder of the number divided by 10.</p>
<p>So let&#8217;s say our number was 34. 10 goes into 34 three times, with a remainder of 4. Now the function runs this value against three cases, those being 1, 2, and 3. Since it is not one of them, the default value is used, which is &#8220;th.&#8221; Thus returning &#8220;4th.&#8221;</p>
<p><strong>Example input:</strong></p>
<pre>
3
10
999
</pre>
<p><strong>Example output:</strong></p>
<pre>
3rd
10th
999th
</pre>
<p>Enjoy!</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=481&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/481/php-ordinalize-numbers-add-suffix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mysql Rows in HTML Option Tag</title>
		<link>http://bgallz.org/458/mysql-rows-html-option-tag/</link>
		<comments>http://bgallz.org/458/mysql-rows-html-option-tag/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 05:06:41 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[option]]></category>
		<category><![CDATA[rows]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=458</guid>
		<description><![CDATA[Let&#8217;s say you want to have a simple HTML &#60;select&#62; form as a drop down for rows in a Mysql table. This could be for things like categories, pages, games, anything you want to have in a drop down to navigate to another page or submit a form. What ever the case is, I&#8217;m going to make a simple layout ...]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you want to have a simple HTML &lt;select&gt; form as a drop down for rows in a Mysql table. This could be for things like categories, pages, games, anything you want to have in a drop down to navigate to another page or submit a form. What ever the case is, I&#8217;m going to make a simple layout for displaying rows returned from a mysql query as &lt;option&gt;&#8217;s in a HTML &lt;select&gt; or drop down.</p>
<p>Before we can grab anything from a mysql database we have to connect to it. Find how to <a href="http://bgallz.org/5/mysql-database-connect/" target="_blank">connect to a mysql database here</a>.</p>
<p>Let&#8217;s make our mysql query first:</p>
<pre>
&lt;?php
// index.php
// Connect to mysql database here!
$sql = mysql_query(&quot;SELECT * FROM table1 ORDER BY id DESC&quot;) or die(mysql_error());
?&gt;
</pre>
<p>This will grab all the rows in &#8220;table1&#8243; ordered by the value of &#8220;id&#8221; descending. You can make this query whatever you want whether you want it ordered differently or with other requirements, etc. Now we will just make a &lt;select&gt; inside of a HTML form that holds each of these values as a option.</p>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Categories&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;./index.php?do=nav&quot; method=&quot;post&quot;&gt;
&lt;strong&gt;Category:&lt;/strong&gt; &lt;select name=&quot;catid&quot; style=&quot;width:250px&quot;&gt;
</pre>
<p>Here is where we will insert our PHP code to call the returned rows of our Mysql query and display them as HTML &lt;option&gt; tags inside of the &lt;select&gt; tag.</p>
<pre>
&lt;?php
// Display mysql rows
if(mysql_num_rows($sql) &gt; 0){
// We have some results!
while($row = mysql_fetch_array($sql)){
echo &quot;&lt;option value=\&quot;&quot;.$row[&quot;id&quot;].&quot;\&quot;&gt;&quot;.$row[&quot;title&quot;].&quot;&lt;/option&gt;&quot;;
}
}
else {
echo &quot;&lt;option value=\&quot;0\&quot;&gt;No categories found.&lt;/option&gt;&quot;;
}
?&gt;
</pre>
<p>Now we close up our HTML and see the finished result!</p>
<pre>
&lt;/select&gt; &lt;input type=&quot;submit&quot; value=&quot;Go!&quot; name=&quot;submit&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>If you have rows returned in you mysql query you will have a HTML drop down that looks like this:</p>
<form><strong>Categories:</strong></p>
<select style="width: 250px;" name="catid">
<option value="1">Category 1</option>
<option value="2">Category 2</option>
<option value="3">Category 3</option>
<option value="4">Category 4</option>
</select>
<input name="submit" type="submit" value="Go!" /> </form>
<p>This HTML form is being submitted to &#8220;<em>index.php?do=nav</em>.&#8221; Of course you can point this where ever you want to do whatever you want with it, but let&#8217;s say we want to have it direct you to a category with PHP. So we are going to run a function on <em>index.php?do=nav</em> that will redirect the viewer to the category.</p>
<pre>
&lt;?php
// Top of index.php
if(isset($_GET[&quot;do&quot;]) &amp;&amp; $_GET[&quot;do&quot;] == &quot;nav&quot;){
// Form submitted
if($_POST[&quot;submit&quot;] &amp;&amp; ((int)$_POST[&quot;catid&quot;])){
// Redirect them to the new page.
header(&quot;Location: ./category?id=&quot;.$_POST[&quot;catid&quot;].&quot;&quot;);
}
}
?&gt;
</pre>
<img src="http://bgallz.org/?ak_action=api_record_view&id=458&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/458/mysql-rows-html-option-tag/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

