<?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; PHP Functions</title>
	<atom:link href="http://bgallz.org/category/code/php-functions/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>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 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 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>
		<item>
		<title>PHP error_reporting() Function</title>
		<link>http://bgallz.org/447/php-error_reporting-function/</link>
		<comments>http://bgallz.org/447/php-error_reporting-function/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 15:38:01 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[error_reporting]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=447</guid>
		<description><![CDATA[The error_reporting() function determines what errors are reported from the current script.
Here is the syntax for this function:
Syntax

error_reporting(report_level);

The report_level parameter is optional and specifies what report level to report for the current script. This can be set by its numeric value or its constant name, however for future versions of PHP it is recommended you use the constant name rather ...]]></description>
			<content:encoded><![CDATA[<p>The error_reporting() function determines what errors are reported from the current script.</p>
<p>Here is the syntax for this function:</p>
<h1>Syntax</h1>
<pre>
error_reporting(report_level);
</pre>
<p>The <em>report_level</em> parameter is optional and specifies what report level to report for the current script. This can be set by its numeric value or its constant name, however for future versions of PHP it is recommended you use the constant name rather than the numeric value.</p>
<style type="text/css">
.data_table { border: 1px solid #ccc; border: 1px solid #ccc; background-color: #fff; }
.data_table td, .data_table th { padding: 3px; border: 1px solid #ddd; }
</style>
<h1>Report Levels</h1>
<table border="1" cellspacing="1" cellpadding="3" width="100%" align="center" class="data_table">
<tr>
<th style="background: #eee; color: #333; font-weight: bold;" width="5%" align="left">Value</th>
<th style="background: #eee; color: #333; font-weight: bold;" width="30%" align="left">Constant</th>
<th style="background: #eee; color: #333; font-weight: bold;" width="65%" align="left">Description</th>
</tr>
<tr>
<td valign="top">1</td>
<td valign="top">E_ERROR</td>
<td valign="top">Fatal run-time errors. Errors that can not be recovered<br />
from. Execution of the script is halted</td>
</tr>
<tr>
<td valign="top">2</td>
<td valign="top">E_WARNING</td>
<td valign="top">Non-fatal run-time errors. Execution of the script is not<br />
halted</td>
</tr>
<tr>
<td valign="top">4</td>
<td valign="top">E_PARSE</td>
<td valign="top">Compile-time parse errors. Parse errors should only be<br />
generated by the parser</td>
</tr>
<tr>
<td valign="top">8</td>
<td valign="top">E_NOTICE</td>
<td valign="top">Run-time notices. The script found something that might be<br />
an error, but could also happen when running a script normally</td>
</tr>
<tr>
<td valign="top">16</td>
<td valign="top">E_CORE_ERROR</td>
<td valign="top">Fatal errors at PHP startup. This is like an E_ERROR in the<br />
PHP core</td>
</tr>
<tr>
<td valign="top">32</td>
<td valign="top">E_CORE_WARNING</td>
<td valign="top">Non-fatal errors at PHP startup. This is like an E_WARNING<br />
in the PHP core</td>
</tr>
<tr>
<td valign="top">64</td>
<td valign="top">E_COMPILE_ERROR</td>
<td valign="top">Fatal compile-time errors. This is like an E_ERROR<br />
generated by the Zend Scripting Engine</td>
</tr>
<tr>
<td valign="top">128</td>
<td valign="top">E_COMPILE_WARNING</td>
<td valign="top">Non-fatal compile-time errors. This is like an E_WARNING<br />
generated by the Zend Scripting Engine</td>
</tr>
<tr>
<td valign="top">256</td>
<td valign="top">E_USER_ERROR</td>
<td valign="top">Fatal user-generated error. This is like an E_ERROR set by<br />
the programmer using the PHP function trigger_error()</td>
</tr>
<tr>
<td valign="top">512</td>
<td valign="top">E_USER_WARNING</td>
<td valign="top">Non-fatal user-generated warning. This is like an E_WARNING<br />
set by the programmer using the PHP function trigger_error()</td>
</tr>
<tr>
<td valign="top">1024</td>
<td valign="top">E_USER_NOTICE</td>
<td valign="top">User-generated notice. This is like an E_NOTICE set by the<br />
programmer using the PHP function trigger_error()</td>
</tr>
<tr>
<td valign="top">2048</td>
<td valign="top">E_STRICT</td>
<td valign="top">Run-time notices. PHP suggest changes to your code to help<br />
interoperability and compatibility of the code</td>
</tr>
<tr>
<td valign="top">4096</td>
<td valign="top">E_RECOVERABLE_ERROR</td>
<td valign="top">Catchable fatal error. This is like an E_ERROR but can be<br />
caught by a user defined handle (see also set_error_handler())</td>
</tr>
<tr>
<td valign="top">8191</td>
<td valign="top">E_ALL</td>
<td valign="top">All errors and warnings, except level E_STRICT (E_STRICT<br />
will be part of E_ALL as of PHP 6.0)</td>
</tr>
</table>
<p>Here is an example of the error_reporting function in PHP:</p>
<pre>
&lt;?php
//Disable error reporting
error_reporting(0);

//Report runtime and notice errors
error_reporting(E_ERROR | E_NOTICE);

//Report all errors
error_reporting(E_ALL);
?&gt;
</pre>
<img src="http://bgallz.org/?ak_action=api_record_view&id=447&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/447/php-error_reporting-function/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP Global Variables with Functions</title>
		<link>http://bgallz.org/335/php-global-variables-with-functions/</link>
		<comments>http://bgallz.org/335/php-global-variables-with-functions/#comments</comments>
		<pubDate>Thu, 27 May 2010 21:59:31 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=335</guid>
		<description><![CDATA[Here we&#8217;re going to take a look at variables inside and outside of PHP functions. It is very easy to make one error with a function and have it return the wrong value. We&#8217;re going to make a simple function named &#8220;func1&#8221; which we&#8217;ll tweak a bit to show how variables are used inside and out of functions in PHP.
Here ...]]></description>
			<content:encoded><![CDATA[<p>Here we&#8217;re going to take a look at variables inside and outside of PHP functions. It is very easy to make one error with a function and have it return the wrong value. We&#8217;re going to make a simple function named &#8220;<strong>func1</strong>&#8221; which we&#8217;ll tweak a bit to show how variables are used inside and out of functions in PHP.</p>
<p>Here is our function, take a look and see if you can tell what the output of the function will be:</p>
<pre>
&lt;?php

function func1(){

}

$var = func1();
echo $var;

?&gt;
</pre>
<p>The output is nothing right now. haha So if you thought it was anything but nothing, that&#8217;s wrong. The function has no code in it whatsoever right now, and the variable &#8220;<strong>$var</strong>&#8221; is set to equal the returned value of the function &#8220;<strong>func1()</strong>.&#8221; Since the function does nothing, $var is equal to nothing. Easy enough. Now let&#8217;s work with some variables.</p>
<pre>
&lt;?php

function func1($var){
return $var; // returning the exact value of $var.
}

$var = func1(&quot;hello&quot;); // $var is equal to the function func1() with parameter &quot;hello&quot;
echo $var;

?&gt;
</pre>
<p>Now, we have a parameter to our PHP function. A <strong>parameter </strong>is any variable that is defined within the function&#8217;s parentheses. You can have many parameters in your functions &#8211; seperated by commas &#8211; but it is  a good idea to keep your functions organized and simple to their purpose. So we have $var as a parameter to <strong>func1()</strong>. You can use these to submit values through a function and work with them inside the function to return a different or desired value. Right now, the function <strong>func1()</strong> is just returning $var. So whatever is put through as $var initially, will be returned back as it was.</p>
<p>So this code will result in the output:</p>
<p><em>hello</em></p>
<p>Let&#8217;s say we want to have a <strong>global variable</strong> we can use in several functions. Global variables are defined as such within a function as previously defined variables outside the function. In the following code we&#8217;ll define <strong>$name</strong> as &#8220;Brian&#8221; and use it in two functions.</p>
<pre>
&lt;?php

$name = &quot;Brian&quot;;

function hello(){
global $name;
return &quot;Hello &quot;.$name.&quot;!&quot;;
}

function goodbye(){
global $name;
return &quot;Goodbye &quot;.$name.&quot;!&quot;;
}

$hello = hello();
$goodbye = goodbye();

echo $hello;
echo &quot;&lt;br/&gt;&quot;;
echo $goodbye;

?&gt;
</pre>
<p>The output of this code will be:</p>
<p><em>Hello Brian!<br />
Goodbye Brian!</em></p>
<p>You can use global variables with PHP pages you include on other PHP pages. For example if you have variables defined on one PHP page, in this example &#8220;variables.php,&#8221; you can call that page to another and globally define variables in your functions to work with them and return what you like.</p>
<p><strong>Variables.php:</strong></p>
<pre>
&lt;?php

$name = &quot;Brian&quot;;
$website = &quot;bgallz.org&quot;;

?&gt;
</pre>
<p>Now on our page we are working on, we&#8217;ll call it &#8220;display.php,&#8221; we&#8217;ll call the page variables.php and use these variables in functions.</p>
<p><strong>Display.php:<br />
</strong>
<pre>
&lt;?php

include(&quot;variables.php&quot;) or die(&quot;Could not find variables.php&quot;);

function hello(){
global $name;
global $website;

return &quot;Hello &quot;.$name.&quot;! Thanks for visiting &quot;.$website.&quot;&quot;;

}

$var = hello();
echo $var;

?&gt;
</pre>
<p>The output of this code will be:</p>
<p><em>Hello Brian! Thanks for visiting bgallz.org.</em></p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=335&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/335/php-global-variables-with-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Timestamps time()</title>
		<link>http://bgallz.org/276/php-timestamps-time/</link>
		<comments>http://bgallz.org/276/php-timestamps-time/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 19:47:18 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://bgallz.org/276/php-timestamps-time/</guid>
		<description><![CDATA[One of the most common ways to capture the current time in PHP scripting is by using the time() function.  This returns the current timestamp which is the number of seconds after  a certain date and time in the past. You can use this when entering a mysql query to note the current time of whatever action you ...]]></description>
			<content:encoded><![CDATA[<p>One of the most common ways to capture the current time in PHP scripting is by using the time() function.  This returns the current timestamp which is the number of seconds after  a certain date and time in the past. You can use this when entering a mysql query to note the current time of whatever action you are capturing.</p>
<p>We must be connected to a Mysql database in order to submit the value(s) to the database. You can <a href="http://bgallz.org/276/php-timestamps-time/" target="_blank">see how to connect to a mysql database here</a>.</p>
<p>For example, lets say we want to capture the current time of when a form is submitted:</p>
<pre>
&lt;?php

if($_POST[&quot;submit&quot;]){
// form is submitted
$username = trim($_POST[&quot;username&quot;];
$password = md5(trim($_POST[&quot;password&quot;]));
// trim the values
$time = time(); // capture the current timestamp to record the time.

// connect to mysql database here!
// granted we are already connected to a mysql database, submit the query
$sql = mysql_query(&quot;INSERT INTO users (username,password,timestamp) VALUES (&#039;$username&#039;,&#039;$password&#039;,&#039;$time&#039;)&quot;) or die(mysql_error());
}

// username,password, and time submitted to the database
</pre>
<p>If we wanted to grab the time that a user is submittted to the database (their registration date/time) we would just use a Mysql query to select the <em>timestamp</em> where the Username field matches a specified value. We will use the <em>date()</em> function to echo the <em>timestamp</em> into a date format. We will use the m/d/Y format:</p>
<ul>
<li><em>d</em> &#8211; Represents the day of the month (01 to 31)</li>
<li><em>m</em> &#8211; Represents a month (01 to 12)</li>
<li><em>Y</em> &#8211; Represents a year (in four digits)</li>
</ul>
<p><a href="http://www.plus2net.com/php_tutorial/php_date_format.php" target="_blank">View a complete list of the PHP date() format list here!</a></p>
<p>Like so:</p>
<pre>
&lt;?php
$sql = mysql_query(&quot;SELECT timestamp AS time FROM users WHERE username = &#039;$username&#039;&quot;) or die(mysql_error());
if(mysql_num_rows($sql) &gt; 0){
$row = mysql_fetch_assoc($sql);
echo &quot;You joined on: &quot;.date(&quot;m/d/Y&quot;,$row[&#039;time&#039;]).&quot;.&quot;;
} else {
echo &quot;User has not joined!&quot;;
}
?&gt;
</pre>
<p>This will output the code as such:</p>
<p>You joined on: 05/31/2010.</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=276&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/276/php-timestamps-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Switch Function</title>
		<link>http://bgallz.org/234/php-switch-function/</link>
		<comments>http://bgallz.org/234/php-switch-function/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:07:37 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=234</guid>
		<description><![CDATA[The function switch() in PHP is used to execute different codes based on a variable&#8217;s value. This is used in place of the IF/ELSE IF statements. A default value is optional and, if specified, is used when no other option is matched. You must include a break; after each case or the following cases will all return true.

&#60;?php

switch($var){

case &#34;blue&#34;:
echo &#34;You ...]]></description>
			<content:encoded><![CDATA[<p>The function <em>switch()</em> in PHP is used to execute different codes based on a variable&#8217;s value. This is used in place of the IF/ELSE IF statements. A default value is optional and, if specified, is used when no other option is matched. You must include a <em>break;</em> after each case or the following cases will all return true.</p>
<pre>
&lt;?php

switch($var){

case &quot;blue&quot;:
echo &quot;You have selected the color blue.&quot;;
break;

case &quot;green&quot;:
echo &quot;You have selected the color green.&quot;;
break;

case &quot;red&quot;:
echo &quot;You have selected the color red.&quot;;
break;

case &quot;yellow&quot;:
echo &quot;You have selected the color yellow.&quot;;
break;

default:
echo &quot;You have not chosen a color.&quot;;

}
?&gt;
</pre>
<p>You can use this with forms and such to determine an action based on a submitted value as well! Here is an example using the <em>switch()</em> function in a form:</p>
<pre>
&lt;form action=&quot;submit.php&quot; method=&quot;post&quot;&gt;
Select your gender: &lt;select name=&quot;gender&quot;&gt;
&lt;option value=&quot;&quot;&gt;Select one...&lt;/option&gt;
&lt;option value=&quot;male&quot;&gt;Male&lt;/option&gt;
&lt;option value=&quot;female&quot;&gt;Female&lt;/option&gt;&lt;/select&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>Now on our PHP side of the script (<strong>submit.php</strong>) we will use the <em>switch()</em> function to evaluate the value.</p>
<pre>
&lt;?php

// submit.php

if($_POST[&#039;submit&#039;]){

$value = $_POST[&#039;gender&#039;];
switch($value){

case &quot;male&quot;:
echo &quot;You are male. Thank you.&quot;;
break;

case &quot;female&quot;:
echo &quot;You are female. Thank you.&quot;;
break;

default:
echo &quot;Please choose your gender.&quot;;

}

}

?&gt;
</pre>
<img src="http://bgallz.org/?ak_action=api_record_view&id=234&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/234/php-switch-function/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

