<?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>PHP-Princess.net &#187; Code Snippets</title>
	<atom:link href="http://php-princess.net/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://php-princess.net</link>
	<description></description>
	<lastBuildDate>Thu, 29 Mar 2012 15:50:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<script type="text/javascript">
if (typeof Meebo == "undefined") {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){

	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'phpprincessnet_ba02xu'});	}</script>	<item>
		<title>Using Google Font API</title>
		<link>http://php-princess.net/2010/06/04/using-google-font-api/</link>
		<comments>http://php-princess.net/2010/06/04/using-google-font-api/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 17:10:09 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Links and Resources]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[fonts]]></category>

		<guid isPermaLink="false">http://php-princess.net/?p=5757</guid>
		<description><![CDATA[One thing I learned at Google I/O that I thought was fun and exciting was their new Google Font API. What does this mean? It means I don&#8217;t have to add text to images using Photoshop anymore. I can just add it directly to the HTML code as plain text and it&#8217;ll look beautiful on [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://php-princess.net/wp-content/uploads/google_font_api.gif" alt="" title="google_font_api" width="196" height="40" class="alignright size-full wp-image-5758" align="right" hspace="5" />One thing I learned at <strong>Google I/O</strong> that I thought was fun and exciting was their new Google Font API. What does this mean? It means I don&#8217;t have to add text to images using Photoshop anymore. I can just add it directly to the HTML code as plain text and it&#8217;ll look beautiful on the page. </p>
<p>This will (1) speed up page loads because text loads faster than images and (2) make the page more accessible (screen readers won&#8217;t need to piece together alt tags of images; instead, it&#8217;ll just read the text directly off the page. (3) The more text you have on a page, the more SEO-friendly it is.</p>
<p>Lucky for us, adding Google fonts to our webpage is quite easy. All you need is to know a bit of CSS and HTML, and how to copy and paste!</p>
<h3>Step 1: Select Font</h3>
<p>Go to the <strong><a href="http://code.google.com/webfonts">Google font directory</a></strong> and choose a font you would like to use. In the sample below, I picked the &#8220;Lobster&#8221; font.</p>
<p><img src="http://php-princess.net/wp-content/uploads/googlefont-lobster.jpg" alt="" title="googlefont-lobster" width="590" height="526" class="alignnone size-full wp-image-5762" style="border: 1px solid gray;" /></p>
<h3>Step 2: Get the Code</h3>
<p>If you like the font, tab over to &#8220;<strong><a href="http://code.google.com/webfonts/family?family=Lobster#code">Get the Code</a></strong>.&#8221; From there, you will get a sample code like this:</p>
<blockquote><p><code>&lt;link href='http://fonts.googleapis.com/css?family=<strong>Lobster</strong>' rel='stylesheet' type='text/css'&gt;&lt;/link&gt;</code>
</p></blockquote>
<p>To include the code into your page, simply copy and paste this code into the header of your HTML page.</p>
<p>If you prefer to include the font it into your CSS stylesheet instead of your HTML header, you can use a code like this instead:</p>
<blockquote><p><code>@import url("http://fonts.googleapis.com/css?family=<strong>Lobster</strong>");</code></p></blockquote>
<h3>Step 3: Add some style!</h3>
<p>Now that you have your font embedded onto your page, it&#8217;s time to give it some style. Create a CSS class and add in your font. </p>
<p>In this sample, I created a class called &#8220;prettyFont&#8221; and made it use the &#8220;Lobster&#8221; font to display, in huge red font. The alternative &#8220;arial and serif&#8221; font were added as a backup in case Google Font API was down; these web-safe fonts will display instead of Lobster in that case.</p>
<blockquote><p><code>.prettyFont { font-family: '<strong>Lobster</strong>', arial, serif; font-size: 3em; color:red; }</code></p></blockquote>
<p>That&#8217;s pretty much it! Adding Google Fonts to your page is as simple as 1-2-3! You can also go even more wild and add shadows, shading, and anything else you can do with HTML + CSS.</p>
<p><img src="http://php-princess.net/wp-content/uploads/googlefontapi.gif" alt="" align="left" hspace="5" />For more information, <strong><a href="http://code.google.com/apis/webfonts/">see the Google Font API documentation</a></strong>. For more sample codes, check out <strong><a href="http://code.google.com/apis/webfonts/docs/getting_started.html">Getting Started with Google Font API</a></strong>. And if you want to dive in deeper and add in italic, bold, and bold italic fonts, see their <strong><a href="http://code.google.com/apis/webfonts/docs/getting_started.html#Further_Reading">further reading section</a></strong>.</p>
<p><map name='google_ad_map_5757_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/5757?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_5757_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=5757&amp;url= http%3A%2F%2Fphp-princess.net%2F2010%2F06%2F04%2Fusing-google-font-api%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2010%2F06%2F04%2Fusing-google-font-api%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-5757-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2010/06/04/using-google-font-api/',title:'Using Google Font API',tweet:'One thing I learned at Google I/O that I thought was fun and exciting was their new Google Font API.',description:'One thing I learned at Google I/O that I thought was fun and exciting was their new Google Font API.'})"><script type='text/javascript'>document.getElementById("post-5757-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=5757&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2010/06/04/using-google-font-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft Office 2007 Files Downloading as .Zip Files</title>
		<link>http://php-princess.net/2008/11/13/microsoft-office-2007-files-downloading-as-zip-files/</link>
		<comments>http://php-princess.net/2008/11/13/microsoft-office-2007-files-downloading-as-zip-files/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 21:48:18 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[problemsolving]]></category>

		<guid isPermaLink="false">http://php-princess.net/?p=1005</guid>
		<description><![CDATA[A colleague IMed me earlier today. She was wondering why her .xlsx document was downloading as a strange .zip file. She had uploaded it into the content management system correctly, but when she tried to test it out, the file looked corrupted. Albert did some digging around and figured that the Microsoft Office 2007 files [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague IMed me earlier today. She was wondering why her .xlsx document was downloading as a strange .zip file. She had uploaded it into the content management system correctly, but when she tried to test it out, the file looked corrupted.</p>
<p><a href="http://albertech.net/?p=24">Albert</a> did some digging around and figured that the Microsoft Office 2007 files extensions were not recognized by Apache. So downloading files like .xlsx, .docx, .pptx, etc. will translate to file<strong>.zip</strong> instead. I did some further browser testing and noticed this problem only appears in IE browsers. It works perfectly in Firefox, Chrome, and Safari.</p>
<p>To fix this problem, you would need to add the extensions to the Apache config file.</p>
<p><strong>Step 1:</strong> Make sure you back up your configuration file (httpd.conf in Apache) or (apache2.conf in Apache2)</p>
<p><strong>Step 2:</strong> Search for the section with the AddType keywords. </p>
<p><strong>Step 3:</strong> Add the following lines:</p>
<p><code><br />
# MIME type fix<br />
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx<br />
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx<br />
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow .pptx<br />
</code></p>
<p>If you load other Microsoft Office 2007 files on your Apache web server, you may want to add additional <a href="http://www.webmasterworld.com/apache/3539138.htm">file extensions</a>.</p>
<p>Thanks for figuring it out <a href="http://albertech.net/">Albert</a>! That solved the mystery behind two work tickets today.</p>
<p><strong>Sources:</strong> <a href="http://albertech.net/?p=24">Albertech.net</a>, <a href="http://www.webmasterworld.com/apache/3539138.htm">MS Office 2007 File Extensions at WebmasterWorld</a></p>
<p><map name='google_ad_map_1005_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1005?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1005_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1005&amp;url= http%3A%2F%2Fphp-princess.net%2F2008%2F11%2F13%2Fmicrosoft-office-2007-files-downloading-as-zip-files%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2008%2F11%2F13%2Fmicrosoft-office-2007-files-downloading-as-zip-files%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-1005-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2008/11/13/microsoft-office-2007-files-downloading-as-zip-files/',title:'Microsoft Office 2007 Files Downloading as .Zip Files',tweet:'A colleague IMed me earlier today. She was wondering why her .xlsx document was downloading as a str',description:'A colleague IMed me earlier today. She was wondering why her .xlsx document was downloading as a str'})"><script type='text/javascript'>document.getElementById("post-1005-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=1005&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2008/11/13/microsoft-office-2007-files-downloading-as-zip-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Email Validation</title>
		<link>http://php-princess.net/2007/08/20/php-email-validation/</link>
		<comments>http://php-princess.net/2007/08/20/php-email-validation/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 00:34:54 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://php-princess.net/2007/08/20/php-email-validation/</guid>
		<description><![CDATA[Note to self, use this for email validation: function isEmail($email) { if(ereg("^([a-zA-Z0-9_\-\.]+)@ ((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)&#124; (([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}&#124;[0-9]{1,3})(\]?)$", $email)) return 1; // If email address is valid else return 0; } Minus all the spaces in the ereg function.]]></description>
			<content:encoded><![CDATA[<p>Note to self, use this for email validation:</p>
<p><code>function isEmail($email)<br />
{<br />
	if(ereg("^([a-zA-Z0-9_\-\.]+)@<br />
          ((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|<br />
          (([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email))<br />
		return 1;		// If email address is valid<br />
	else<br />
		return 0;<br />
}<br />
</code></p>
<p>Minus all the spaces in the ereg function.</p>
<p><map name='google_ad_map_595_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/595?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_595_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=595&amp;url= http%3A%2F%2Fphp-princess.net%2F2007%2F08%2F20%2Fphp-email-validation%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2007%2F08%2F20%2Fphp-email-validation%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-595-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2007/08/20/php-email-validation/',title:'PHP Email Validation',tweet:'Note to self, use this for email validation: function isEmail($email) { 	if(ereg(\"^([a-zA-Z0-9_\\-\\.]',description:'Note to self, use this for email validation: function isEmail($email) { 	if(ereg(\"^([a-zA-Z0-9_\\-\\.]'})"><script type='text/javascript'>document.getElementById("post-595-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=595&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2007/08/20/php-email-validation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS 3: Substring Matching Attribute Selectors</title>
		<link>http://php-princess.net/2007/03/16/css-3-substring-matching-attribute-selectors/</link>
		<comments>http://php-princess.net/2007/03/16/css-3-substring-matching-attribute-selectors/#comments</comments>
		<pubDate>Sat, 17 Mar 2007 04:37:55 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tips and Tutorials]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://php-princess.net/2007/03/16/css-3-substring-matching-attribute-selectors/</guid>
		<description><![CDATA[I was reading up on CSS 3&#8242;s Substring matching attribute selectors and discovered a fun way to reference anchor links! Web links can be a variety of files. PDF, DOC, and HTML are some of the familiar ones. I was wondering if we could put a small icon to denote what type of file is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://php-princess.net/wp-content/uploads/css-icon.png" alt="css-icon" title="css-icon" class="alignright size-full wp-image-1774" />I was reading up on <a href="http://www.w3.org/TR/css3-selectors/#attribute-representation">CSS 3&#8242;s Substring matching attribute selectors</a> and discovered a fun way to reference anchor links!</p>
<p>Web links can be a variety of files.  PDF, DOC, and HTML are some of the familiar ones.  I was wondering if we could put a small icon to denote what type of file is being downloaded, and with CSS3, it&#8217;s quite possible.</p>
<p>Create an HTML file.  Between the &lt;head&gt; tags, put</p>
<pre class="brush:css">
&lt;style&gt;
body {
  font-size: .9em; font-weight: bold;
}
a { color: blue; line-height: 1.5em; }
a[href$=".html"] {
   padding-left:20px; background-image:url(html.gif);
   background-repeat: no-repeat;
}
a[href$=".pdf"] {
   padding-left:20px; background-image:url(pdf.gif);
   background-repeat: no-repeat;
}
a[href$=".doc"] {
   padding-left:20px; background-image:url(msword.gif);
   background-repeat: no-repeat;
}
&lt;/style&gt;</pre>
<p>and between the &lt;body&gt; tags, put:</p>
<pre class="brush:html">&lt;ul&gt;
&lt;li&gt;&lt;a href="myfile.html"&gt;My HTML File&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="myfile.pdf"&gt;My PDF File&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="myfile.doc"&gt;My Word Doc File&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://php-princess.net"&gt;Any Link&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>Save the file as mytest.html (and download these three images as well &#8212; <img src="http://php-princess.net/wp-content/uploads/msword.gif" alt="MS Word" /> <img src="http://php-princess.net/wp-content/uploads/pdf.gif" alt="PDF" /> <img src="http://php-princess.net/wp-content/uploads/html.gif" alt="HTML" />) and open it up in Firefox 2.0.  You will then see something that looks like this:</p>
<p><img src="http://php-princess.net/wp-content/uploads/css3-links.jpg" alt="CSS 3 Links" /><br />
Isn&#8217;t that great?  The padding attribute moves the link 20px to the right.  And the background-repeat attribute makes sure that image doesn&#8217;t repeat. So when I link a PDF file on my website, an image of a PDF file automatically shows next to the link.  What a time-saver. :)  The only drawback to this is that CSS3 isn&#8217;t fully implemented in all of today&#8217;s browser.  It seems that Firefox 2.0 is ahead in the game.  MSIE 7.0 and browsers below do not render CSS3 correctly.  But it is a nice tip.  Hopefully the next generation of browsers will render CSS3 the way it&#8217;s suppose to.</p>
<p><map name='google_ad_map_451_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/451?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_451_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=451&amp;url= http%3A%2F%2Fphp-princess.net%2F2007%2F03%2F16%2Fcss-3-substring-matching-attribute-selectors%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2007%2F03%2F16%2Fcss-3-substring-matching-attribute-selectors%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-451-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2007/03/16/css-3-substring-matching-attribute-selectors/',title:'CSS 3: Substring Matching Attribute Selectors',tweet:'I was reading up on CSS 3&#8242;s Substring matching attribute selectors and discovered a fun way to',description:'I was reading up on CSS 3&#8242;s Substring matching attribute selectors and discovered a fun way to'})"><script type='text/javascript'>document.getElementById("post-451-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=451&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2007/03/16/css-3-substring-matching-attribute-selectors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Connect to a MySQL Database using PHP</title>
		<link>http://php-princess.net/2005/03/29/how-to-connect-to-a-database-using-php-and-mysql/</link>
		<comments>http://php-princess.net/2005/03/29/how-to-connect-to-a-database-using-php-and-mysql/#comments</comments>
		<pubDate>Tue, 29 Mar 2005 20:34:38 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts and Coding]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://daynah.php-princess.net/?p=249</guid>
		<description><![CDATA[I was helping my coworker yesterday to create her first PHP-Database program. She already knew how phpMyAdmin worked, so I created a sample page for her to show how to connect to the database and then retrieve data from a query. Maybe this sample page could help you too. I commented as much of the [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://php-princess.net/wp-content/uploads/tn-php.png" title="PHP" class="alignright" width="70" height="70" />I was helping my coworker yesterday to create her first PHP-Database program.  She already knew how phpMyAdmin worked, so I created a sample page for her to show how to connect to the database and then retrieve data from a query.  Maybe this sample page could help you too.  I commented as much of the code as I could.  Let me know if you have any questions.</p>
<p><span id="more-249"></span></p>
<pre class="brush:php">
&lt;?php

/*
	Purpose: This file demonstrates how to run
		and display a mySQL query using PHP.
	Author : Daynah
	Created: 2005/03/28
*/

// Variables for database
$username     = "TestUser";
$dbpword      = "TestPassword";
$database     = "test_database_name";
$host         = "localhost";

// Connect to the database
$db = mysql_connect($host, $username, $dbpword )
	or die ("ERROR: " .mysql_error());
$connection = mysql_select_db( $database, $db );

// Run a query
$query = "SELECT * FROM myTestTable";		// The mysql statement
$result = mysql_query($query);				// The results of a query
$num_rows = mysql_num_rows($result);		// Number of rows of data

// Start the table to display the data
echo '&lt;table&gt;';

// If there is data in that query, display the data
if($num_rows)
{
	// PHP Script to iterate through the data in the database
	// This will print out each Table Row
	/*	|   ID	| Name	|  Address	|
		-----------------------------
			1	  Name1		Address1
			2	  Name2		Address2
		Assuming there are three fields in the table -- ID, Name, and Address
	*/
	while($myData = mysql_fetch_object($result)
	{
		// Print Each Row of Data -- ID, Name, Address
		echo '&lt;tr&gt;&lt;td&gt;'. $myData-&gt;ID.'&lt;/td&gt;
				  &lt;td&gt;'. $myData-&gt;Name.'&lt;/td&gt;
				  &lt;td&gt;'. $myData-&gt;Address.'&lt;/td&gt;
			  &lt;/tr&gt;';
	}
}

// If there is no data in the database.
else
{
	echo '&lt;tr&gt;&lt;td&gt;Sorry, there is no data in the database.&lt;/td&gt;&lt;/tr&gt;';
}

// Close the table tag
echo '&lt;/table&gt;';

// Close Mysql Connection
mysql_close();

?&gt;
</pre>
<p><map name='google_ad_map_249_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/249?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_249_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=249&amp;url= http%3A%2F%2Fphp-princess.net%2F2005%2F03%2F29%2Fhow-to-connect-to-a-database-using-php-and-mysql%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2005%2F03%2F29%2Fhow-to-connect-to-a-database-using-php-and-mysql%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-249-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2005/03/29/how-to-connect-to-a-database-using-php-and-mysql/',title:'How to Connect to a MySQL Database using PHP',tweet:'I was helping my coworker yesterday to create her first PHP-Database program.  She already knew how ',description:'I was helping my coworker yesterday to create her first PHP-Database program.  She already knew how '})"><script type='text/javascript'>document.getElementById("post-249-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=249&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2005/03/29/how-to-connect-to-a-database-using-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing last character of a string</title>
		<link>http://php-princess.net/2004/06/30/removing-last-character-of-a-string/</link>
		<comments>http://php-princess.net/2004/06/30/removing-last-character-of-a-string/#comments</comments>
		<pubDate>Wed, 30 Jun 2004 17:09:18 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://daynah.php-princess.net/?p=165</guid>
		<description><![CDATA[I had a string that looked like: 2;4;6;7; The string is dynamic, so it could also be: 3;5;2;8;9; I needed to remove the last ; (semicolon) from the string but wasn&#8217;t sure what the best method of doing this was. I thought about using the strlen() (string length) function. Get the value of how long [...]]]></description>
			<content:encoded><![CDATA[<p>I had a string that looked like: </p>
<p><code>2;4;6;7;</code></p>
<p>The string is dynamic, so it could also be:</p>
<p><code>3;5;2;8;9;</code></p>
<p>I needed to remove the last ; (semicolon) from the string but wasn&#8217;t sure what the best method of doing this was.  I thought about using the <a href="http://php.net/strlen">strlen()</a> (string length) function.  Get the value of how long the string is, and then removed the last character using <a href="http://php.net/substr">substr()</a>.  The task seems a bit tedious and unefficient though.  </p>
<p>So I searched <a href="http://www.google.com">Google</a> to find the best method, and stumbled upon <a href="http://www.wellho.net/forum/Writing-PHP/Removing-last-character-of-a-string.html">the answer to my question</a> &#8212; How do you remove the last character of a string?</p>
<p>The solution is to use:<br />
<code>$outgoing = substr_replace($incoming,"",-1);</code></p>
<p>So if I use:<br />
<code>$outgoing = substr_replace('3;5;2;8;9;',"",-1);</code></p>
<p>My output would be:<br />
<code>3;5;2;8;9</code></p>
<p>Exactly what I was looking for! Thank you <a href="http://www.wellho.net/forum/">Graham Ellis</a>! </p>
<p><map name='google_ad_map_165_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/165?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_165_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=165&amp;url= http%3A%2F%2Fphp-princess.net%2F2004%2F06%2F30%2Fremoving-last-character-of-a-string%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2004%2F06%2F30%2Fremoving-last-character-of-a-string%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-165-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2004/06/30/removing-last-character-of-a-string/',title:'Removing last character of a string',tweet:'I had a string that looked like:  2;4;6;7; The string is dynamic, so it could also be: 3;5;2;8;9; I ',description:'I had a string that looked like:  2;4;6;7; The string is dynamic, so it could also be: 3;5;2;8;9; I '})"><script type='text/javascript'>document.getElementById("post-165-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=165&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2004/06/30/removing-last-character-of-a-string/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Animation using CSS</title>
		<link>http://php-princess.net/2004/05/06/animation-using-css/</link>
		<comments>http://php-princess.net/2004/05/06/animation-using-css/#comments</comments>
		<pubDate>Thu, 06 May 2004 21:57:07 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Links and Resources]]></category>

		<guid isPermaLink="false">http://daynah.php-princess.net/?p=145</guid>
		<description><![CDATA[I was reading this article called &#8220;CSS Sprites: Image Slicing&#8217;s Kiss of Death&#8221; which shows how we can animate images, using only CSS and no javascript. I decided to try it out for myself, and played with the code for a bit. I came up with this this example using an image. The amazing thing [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading this article called &#8220;<a href="http://alistapart.com/articles/sprites/">CSS Sprites: Image Slicing&#8217;s Kiss of Death</a>&#8221; which shows how we can animate images, using only CSS and no javascript.  I decided to try it out for myself, and played with the code for a bit.  I came up with this <a href="http://tutorials.php-princess.net/css/animated.html">this example</a> using an image.  The amazing thing part is that only <a href="http://tutorials.php-princess.net/css/phpp.jpg">one image</a> was used.  The coding for this trick is very condensed and much shorter than a javascript.  One advantage this has over using javascript is that it is much faster.  There&#8217;s no delay with multiple image swapping.  Instead, css displays a different part of one image.</p>
<p><a href="http://alistapart.com/articles/sprites/">Read more</a> about this CSS trick and see if you can give your webpage a little more life. :)</p>
<p><map name='google_ad_map_145_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/145?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_145_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=145&amp;url= http%3A%2F%2Fphp-princess.net%2F2004%2F05%2F06%2Fanimation-using-css%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2004%2F05%2F06%2Fanimation-using-css%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-145-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2004/05/06/animation-using-css/',title:'Animation using CSS',tweet:'I was reading this article called &#8220;CSS Sprites: Image Slicing&#8217;s Kiss of Death&#8221; whi',description:'I was reading this article called &#8220;CSS Sprites: Image Slicing&#8217;s Kiss of Death&#8221; whi'})"><script type='text/javascript'>document.getElementById("post-145-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=145&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2004/05/06/animation-using-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Easter Date</title>
		<link>http://php-princess.net/2004/03/29/easter-date/</link>
		<comments>http://php-princess.net/2004/03/29/easter-date/#comments</comments>
		<pubDate>Mon, 29 Mar 2004 17:42:45 +0000</pubDate>
		<dc:creator>daynah</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://daynah.php-princess.net/?p=140</guid>
		<description><![CDATA[Are you wondering what day Easter falls on this year? Not to worry, a simple PHP script can figure it out faster than you flipping a calendar. heh Ok, maybe not, but it&#8217;s still a neat trick. :) Just put this code in a php file, uploaded and see for yourself. < ? echo date [...]]]></description>
			<content:encoded><![CDATA[<p>Are you wondering what day Easter falls on this year?  Not to worry, a simple PHP script can figure it out faster than you flipping a calendar.  heh Ok, maybe not, but it&#8217;s still a neat trick. :)</p>
<p>Just put this code in a php file, uploaded and see for yourself.<br />
<code style="font-size: 12px;">< ? echo date ("M-d-Y", easter_date(2004)); ?></></code></p>
<p><a href="http://board.php-princess.net/index.php?showtopic=67&#038;hl=easter">More information here</a>.</p>
<p><map name='google_ad_map_140_5ca5e442dc272ca0'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/140?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_140_5ca5e442dc272ca0' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=140&amp;url= http%3A%2F%2Fphp-princess.net%2F2004%2F03%2F29%2Feaster-date%2F' /></p><div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fphp-princess.net%2F2004%2F03%2F29%2Feaster-date%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><img style='display:none' id="post-140-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://php-princess.net/2004/03/29/easter-date/',title:'Easter Date',tweet:'Are you wondering what day Easter falls on this year?  Not to worry, a simple PHP script can figure ',description:'Are you wondering what day Easter falls on this year?  Not to worry, a simple PHP script can figure '})"><script type='text/javascript'>document.getElementById("post-140-blankimage").onload();</script><img src="http://php-princess.net/?ak_action=api_record_view&id=140&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://php-princess.net/2004/03/29/easter-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

