<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Code2Design</title>
  <subtitle>Coding and Designing the Best!</subtitle>
  <link rel="alternate" type="text/html" href="http://www.code2design.com"/>
  <link rel="self" type="application/atom+xml" href="http://www.code2design.com/atom/feed"/>
  <id>http://www.code2design.com/atom/feed</id>
  <updated>2007-02-25T14:02:58-05:00</updated>
  <entry>
    <title>MD5, hashes, passwords, salts and more</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/david/md5_hashes_passwords_salts_and_more" />
    <id>http://www.code2design.com/david/md5_hashes_passwords_salts_and_more</id>
    <published>2008-04-08T16:04:30-04:00</published>
    <updated>2008-04-08T16:04:54-04:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="PHP" />
    <category term="Hacking" />
    <summary type="html"><![CDATA[<p>1) You need to salt your passwords.<br />
"Assume a user's secret key is stolen and he is known to use one of 200,000 English words as his password. The system uses a 32-bit salt (like md5). Because of this salt, the attacker's pre-calculated hashes are of no value. He/she must calculate the hash of each word with each of 2^32 (4,294,967,296) possible salts appended until a match is found. The total number of possible inputs can be obtained by multiplying the number of words in the dictionary with the number of possible salts:<br />
2^{32} \times 200 000 = 8.58993459 \times 10^{14}<br />
To complete a brute-force attack, the attacker must now compute about 800 trillion hashes, instead of only 200,000. Even though the password itself is known to be simple, the secret salt makes breaking the password radically more difficult." - <a href="http://en.wikipedia.org/wiki/Salt_"><a href="http://en.wikipedia.org/wiki/Salt_">http://en.wikipedia.org/wiki/Salt_</a></a>(cryptography)</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>1) You need to salt your passwords.</p>
<p>"Assume a user's secret key is stolen and he is known to use one of 200,000 English words as his password. The system uses a 32-bit salt (like md5). Because of this salt, the attacker's pre-calculated hashes are of no value. He/she must calculate the hash of each word with each of 2^32 (4,294,967,296) possible salts appended until a match is found. The total number of possible inputs can be obtained by multiplying the number of words in the dictionary with the number of possible salts:</p>
<p>2^{32} \times 200 000 = 8.58993459 \times 10^{14}</p>
<p>To complete a brute-force attack, the attacker must now compute about 800 trillion hashes, instead of only 200,000. Even though the password itself is known to be simple, the secret salt makes breaking the password radically more difficult." - <a href="http://en.wikipedia.org/wiki/Salt_">http://en.wikipedia.org/wiki/Salt_</a>(cryptography)</p>
<p>2) Now that I got that off my chest I recommend this awesome PHP class <a href="http://www.openwall.com/phpass/">http://www.openwall.com/phpass/</a> as even WORDPRESS has started using it.</p>
<p>3) Plain md5 is just too simple to crack - it is like WEP in WIFI: <a href="http://md5.rednoize.com/">http://md5.rednoize.com/</a></p>
<p>4) Rainbow Tables can kill your simple PHP scripts: <a href="http://www.antsight.com/zsl/rainbowcrack/">http://www.antsight.com/zsl/rainbowcrack/</a><br />
<a href="http://en.wikipedia.org/wiki/Rainbow_table">http://en.wikipedia.org/wiki/Rainbow_table</a></p>
<p>So please, I don't want to see anyone still using plain md5() hashes - at least use a salt! </p>
<p><a href="http://www.lightbluetouchpaper.org/2007/11/16/google-as-a-password-cracker/">http://www.lightbluetouchpaper.org/2007/11/16/google-as-a-password-cracker/</a><br />
<a href="http://phpsec.org/articles/2005/password-hashing.html">http://phpsec.org/articles/2005/password-hashing.html</a></p>
    ]]></content>
  </entry>
  <entry>
    <title>Arrays by reference</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/arrays_by_reference" />
    <id>http://www.code2design.com/tutorial/arrays_by_reference</id>
    <published>2008-01-17T15:18:24-05:00</published>
    <updated>2008-01-17T15:27:53-05:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="Beginning PHP Tutorials" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter-->
<p>I have been using lots of functions to create and check my variables and arrays lately. Along these lines, I thought I would take some time to share how the concept of "passing values by reference" works. </p>
<p>Basically, if you are anything like me you are always passing functions values and then having that function "return" a value. While there is nothing wrong with this approach, there is often an easier way to work with values in functions. Besides making values "<a href="http://us.php.net/global">global</a>", you can also pass a function a value by reference.</p>
<p>Here is the standard way most people would work with a value in a function and then collect the functions return value.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>I have been using lots of functions to create and check my variables and arrays lately. Along these lines, I thought I would take some time to share how the concept of "passing values by reference" works. </p>
<p>Basically, if you are anything like me you are always passing functions values and then having that function "return" a value. While there is nothing wrong with this approach, there is often an easier way to work with values in functions. Besides making values "<a href="http://us.php.net/global">global</a>", you can also pass a function a value by reference.</p>
<p>Here is the standard way most people would work with a value in a function and then collect the functions return value.</p>
<p><!--break--></p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /><br /></font><font color="#FF8000">////////////////////////////////<br />//&nbsp;Standard&nbsp;Function<br />////////////////////////////////<br /><br />//Lets&nbsp;create&nbsp;a&nbsp;variable;<br /></font><font color="#0000BB">$my_variable&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">''</font><font color="#007700">;<br /><br /></font><font color="#FF8000">//Create&nbsp;the&nbsp;"add_key"&nbsp;function<br /></font><font color="#007700">function&nbsp;</font><font color="#0000BB">add_key</font><font color="#007700">(</font><font color="#0000BB">$key</font><font color="#007700">)&nbsp;{<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; </font><font color="#FF8000">//Create&nbsp;an&nbsp;new&nbsp;array();<br />&nbsp; &nbsp; </font><font color="#0000BB">$array&nbsp;</font><font color="#007700">=&nbsp;array();<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; </font><font color="#FF8000">//Ad&nbsp;a&nbsp;key&nbsp;called&nbsp;"new_key"&nbsp;to&nbsp;the&nbsp;array<br />&nbsp; &nbsp; </font><font color="#0000BB">$array</font><font color="#007700">[</font><font color="#0000BB">$key</font><font color="#007700">]&nbsp;=&nbsp;</font><font color="#DD0000">'value'</font><font color="#007700">;<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; </font><font color="#FF8000">//return&nbsp;the&nbsp;$array<br />&nbsp; &nbsp; </font><font color="#007700">return&nbsp;</font><font color="#0000BB">$array</font><font color="#007700">;<br />}<br /><br /></font><font color="#FF8000">//Run&nbsp;the&nbsp;function&nbsp;"add_key()"&nbsp;and&nbsp;place&nbsp;the&nbsp;output&nbsp;into&nbsp;<br />//$my_variable&nbsp;turning&nbsp;it&nbsp;from&nbsp;an&nbsp;empty&nbsp;variable,&nbsp;into&nbsp;an&nbsp;array!<br />//In&nbsp;other&nbsp;words,&nbsp;$my_variable&nbsp;is&nbsp;now&nbsp;an&nbsp;array&nbsp;with&nbsp;1&nbsp;key&nbsp;called&nbsp;"new_key";<br /></font><font color="#0000BB">$my_variable&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">add_key</font><font color="#007700">(</font><font color="#DD0000">'new_key'</font><font color="#007700">);<br /><br /><br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>$my_variable is now an array ready for you to use in the rest of your script. If you were to run the <a href="http://php.net/print_r" target="_blank">print_r()</a> function right now you would see that $my_variable looks like the following to PHP.</p>
<p><div class="codeblock"><code>Array <br />(<br />    [new_key] =&gt; value<br />)</code></div></p>
<p>So now that we're all "on-the-same-page" so to speak, I want to show you how you can use PHP to cut out a little junk from your script. First though, we need to cover the "&amp;" (and) character. The "&amp;" character means that you aren't working with the variable/array/etc. - you are only working with a pointer to that variable/array/etc. In other words, if you mess with something that has a "&amp;" in front of it you are following that $variables sign to another variables value in the computers memory and changing it!</p>
<blockquote><p>
References in PHP are a means to access the same variable content by different names... ...Note that in PHP, variable name and variable content are different, so the same content can have different names. - <a href="http://php.net">php.net</a>
</p></blockquote>
<p>If you are lost look at this:<br />
<div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /><br />$foo&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'Hello'</font><font color="#007700">;<br /></font><font color="#0000BB">$bar&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'World'</font><font color="#007700">;&nbsp;<br />print&nbsp;</font><font color="#0000BB">$foo&nbsp;</font><font color="#007700">.&nbsp;</font><font color="#DD0000">"&nbsp;"&nbsp;</font><font color="#007700">.&nbsp;</font><font color="#0000BB">$bar</font><font color="#007700">;<br /></font><font color="#FF8000">//Prints&nbsp;"Hello&nbsp;World"<br /><br />//Change&nbsp;$bar&nbsp;to&nbsp;equal&nbsp;"Hello&nbsp;My&nbsp;World"<br /></font><font color="#0000BB">$bar&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'Hello&nbsp;My&nbsp;World'</font><font color="#007700">;<br /></font><font color="#FF8000">//Change&nbsp;$foo&nbsp;to&nbsp;equal&nbsp;the&nbsp;value&nbsp;of&nbsp;a&nbsp;variable&nbsp;called&nbsp;"$bar"<br /></font><font color="#0000BB">$foo&nbsp;</font><font color="#007700">=&nbsp;&amp;</font><font color="#0000BB">$bar</font><font color="#007700">;<br /><br />print&nbsp;</font><font color="#0000BB">$foo</font><font color="#007700">;<br /></font><font color="#FF8000">//Finds&nbsp;the&nbsp;value&nbsp;of&nbsp;$bar,&nbsp;and&nbsp;Prints&nbsp;"Hello&nbsp;My&nbsp;World"<br /></font><font color="#007700">print&nbsp;</font><font color="#0000BB">$bar</font><font color="#007700">;<br /></font><font color="#FF8000">//Prints&nbsp;"Hello&nbsp;My&nbsp;World"<br /><br />//Change&nbsp;$bar&nbsp;to&nbsp;equal&nbsp;"This&nbsp;is&nbsp;bar"<br /></font><font color="#0000BB">$bar&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'This&nbsp;is&nbsp;bar'</font><font color="#007700">;<br /><br />print&nbsp;</font><font color="#0000BB">$foo</font><font color="#007700">;<br /></font><font color="#FF8000">//Finds&nbsp;the&nbsp;value&nbsp;of&nbsp;$bar,&nbsp;and&nbsp;Prints&nbsp;"This&nbsp;is&nbsp;bar"<br /></font><font color="#007700">print&nbsp;</font><font color="#0000BB">$bar</font><font color="#007700">;<br /></font><font color="#FF8000">//Prints&nbsp;"This&nbsp;is&nbsp;bar"<br /><br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>As you can see, from now on $foo will always be eqaul to whatever $bar is equal too! This is quite a useful feature if it is used in the right way! </p>
<p>Taking our first block of code lets change it to use this new type of "variable reference" thinking.<br />
<div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /><br /></font><font color="#FF8000">////////////////////////////////<br />//&nbsp;Simple&nbsp;Function&nbsp;Reference<br />////////////////////////////////<br /><br />//Lets&nbsp;create&nbsp;a&nbsp;variable;<br /></font><font color="#0000BB">$my_variable&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">''</font><font color="#007700">;<br /><br /></font><font color="#FF8000">//Create&nbsp;the&nbsp;"add_key"&nbsp;function&nbsp;and&nbsp;set&nbsp;the<br />//value&nbsp;of&nbsp;to&nbsp;$array&nbsp;to&nbsp;whatever&nbsp;variable&nbsp;was&nbsp;given<br />//to&nbsp;the&nbsp;function.<br /></font><font color="#007700">function&nbsp;</font><font color="#0000BB">add_key2</font><font color="#007700">(&amp;</font><font color="#0000BB">$array</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$key</font><font color="#007700">)&nbsp;{<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; </font><font color="#FF8000">//This&nbsp;now&nbsp;changes&nbsp;$my_variable&nbsp;into&nbsp;an&nbsp;array<br />&nbsp; &nbsp; </font><font color="#0000BB">$array&nbsp;</font><font color="#007700">=&nbsp;array();<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; </font><font color="#FF8000">//Ad&nbsp;a&nbsp;key&nbsp;called&nbsp;"new_key"&nbsp;to&nbsp;$array,&nbsp;which&nbsp;points&nbsp;to&nbsp;$my_variable<br />&nbsp; &nbsp; //So&nbsp;add&nbsp;a&nbsp;new&nbsp;key&nbsp;to&nbsp;$my_variable!<br />&nbsp; &nbsp; </font><font color="#0000BB">$array</font><font color="#007700">[</font><font color="#0000BB">$key</font><font color="#007700">]&nbsp;=&nbsp;</font><font color="#DD0000">'value'</font><font color="#007700">;<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; </font><font color="#FF8000">//There&nbsp;is&nbsp;nothing&nbsp;to&nbsp;return&nbsp;so&nbsp;we&nbsp;don't&nbsp;need&nbsp;this.<br />&nbsp; &nbsp; //return&nbsp;$array;<br /></font><font color="#007700">}<br /><br /></font><font color="#FF8000">//Run&nbsp;the&nbsp;function&nbsp;"add_key2()"&nbsp;which&nbsp;works&nbsp;with&nbsp;a&nbsp;reference&nbsp;to&nbsp;<br />//$my_variable&nbsp;in&nbsp;real&nbsp;time&nbsp;so&nbsp;when&nbsp;add_key&nbsp;is&nbsp;done&nbsp;running,&nbsp;<br />//$my_variable&nbsp;is&nbsp;already&nbsp;updated!<br /></font><font color="#0000BB">add_key2</font><font color="#007700">(</font><font color="#0000BB">$my_variable</font><font color="#007700">,&nbsp;</font><font color="#DD0000">'new_key'</font><font color="#007700">);<br /><br /><br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>$my_variable was transformed into an array by add_key2. Because the first part of the function had a "&amp;" in front of the value to pass the function. That &amp; means that whenever add_key2 worked with "$array", it was really working with "$my_variable"! If you were to run the <a href="http://php.net/print_r" target="_blank">print_r()</a> function right now you would see that $my_variable looks like the following to PHP.</p>
<p><div class="codeblock"><code>Array <br />(<br />    [new_key] =&gt; value<br />)</code></div></p>
<p>So both methods accomplish the same thing just in different ways. Below is a more complex function I built for <a href="http://codexplorer.com">CodeXplorer</a> that will add values to any array you tell it. You might need to download it and run it if you have trouble following the code.</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /><br /><br /></font><font color="#FF8000">////////////////////////////////<br />//&nbsp;Complex&nbsp;Function&nbsp;Reference<br />////////////////////////////////<br /><br /><br />///////////////////////////////////////////////////////////<br />//&nbsp;A&nbsp;function&nbsp;to&nbsp;set&nbsp;multiple&nbsp;array&nbsp;variables&nbsp;if&nbsp;they&nbsp;don't&nbsp;exist.<br />///////////////////////////////////////////////////////////<br /></font><font color="#007700">function&nbsp;</font><font color="#0000BB">create_array_keys</font><font color="#007700">(&amp;</font><font color="#0000BB">$array</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$keys</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$value</font><font color="#007700">=</font><font color="#DD0000">''</font><font color="#007700">)&nbsp;{<br />&nbsp; &nbsp; foreach&nbsp;(</font><font color="#0000BB">$keys&nbsp;</font><font color="#007700">as&nbsp;</font><font color="#0000BB">$key</font><font color="#007700">)&nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#FF8000">//if&nbsp;the&nbsp;key&nbsp;is&nbsp;not&nbsp;in&nbsp;the&nbsp;array,&nbsp;create&nbsp;it!<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#007700">if&nbsp;(!</font><font color="#0000BB">array_key_exists</font><font color="#007700">(</font><font color="#0000BB">$key</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$array</font><font color="#007700">))&nbsp;{&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$array</font><font color="#007700">[</font><font color="#0000BB">$key</font><font color="#007700">]&nbsp;=&nbsp;</font><font color="#0000BB">$value</font><font color="#007700">;&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; </font><font color="#FF8000">//There&nbsp;is&nbsp;nothing&nbsp;to&nbsp;return&nbsp;(everything&nbsp;is&nbsp;done&nbsp;by&nbsp;reference).<br /></font><font color="#007700">}<br /><br /></font><font color="#FF8000">//Create&nbsp;my&nbsp;empty&nbsp;array<br /></font><font color="#0000BB">$my_array&nbsp;</font><font color="#007700">=&nbsp;array();<br /><br /></font><font color="#FF8000">//create&nbsp;an&nbsp;array&nbsp;of&nbsp;keys&nbsp;I&nbsp;want&nbsp;to&nbsp;add&nbsp;to&nbsp;the&nbsp;array<br /></font><font color="#0000BB">$keys&nbsp;</font><font color="#007700">=&nbsp;array(</font><font color="#DD0000">'key_1'</font><font color="#007700">,&nbsp;</font><font color="#DD0000">'key_2'</font><font color="#007700">,&nbsp;</font><font color="#DD0000">'key_3'</font><font color="#007700">,&nbsp;</font><font color="#DD0000">'key_4'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">//See&nbsp;what&nbsp;$my_array&nbsp;looks&nbsp;like<br /></font><font color="#007700">print&nbsp;</font><font color="#DD0000">'&lt;pre&gt;'</font><font color="#007700">;<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$my_array</font><font color="#007700">);<br />print&nbsp;</font><font color="#DD0000">'&lt;/pre&gt;'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">//If&nbsp;the&nbsp;following&nbsp;values&nbsp;are&nbsp;not&nbsp;set,&nbsp;create&nbsp;them&nbsp;in&nbsp;the&nbsp;array&nbsp;"$my_array"&nbsp;and&nbsp;set&nbsp;them&nbsp;to&nbsp;"TRUE".<br /></font><font color="#0000BB">create_array_keys</font><font color="#007700">(</font><font color="#0000BB">$my_array</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$keys</font><font color="#007700">,&nbsp;</font><font color="#0000BB">true</font><font color="#007700">);<br /><br /></font><font color="#FF8000">//See&nbsp;what&nbsp;$my_array&nbsp;looks&nbsp;like&nbsp;now!<br /></font><font color="#007700">print&nbsp;</font><font color="#DD0000">'&lt;pre&gt;'</font><font color="#007700">;<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$my_array</font><font color="#007700">);<br />print&nbsp;</font><font color="#DD0000">'&lt;/pre&gt;'</font><font color="#007700">;<br /><br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>If you ran the above code you would see the following output.<br />
<div class="codeblock"><code>&lt;pre&gt;<br />Array<br />(<br />)<br />&lt;/pre&gt;<br />&lt;pre&gt;<br />Array<br />(<br />    [key_1] =&gt; 1<br />    [key_2] =&gt; 1<br />    [key_3] =&gt; 1<br />    [key_4] =&gt; 1<br />)<br />&lt;/pre&gt;</code></div></p>
<p>So I hope this lesson helps you to better understand how to use PHP's powerful references to avoid having to pass variables around different functions. With references you can simply run a function and know that the variable is being updated automatically. If you want more information on this topic you can visit the PHP manual at <a href="http://us3.php.net/manual/en/functions.arguments.php#functions.arguments.by-reference" target="_blank">php.net - Arguments passed by reference</a> and <a href="http://us3.php.net/manual/en/language.references.php">php.net - References Explained</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Convert MySQL Tables to SQLite Tables</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/convert_mysql_tables_to_sqlite_tables" />
    <id>http://www.code2design.com/tutorial/convert_mysql_tables_to_sqlite_tables</id>
    <published>2007-12-13T15:36:36-05:00</published>
    <updated>2007-12-13T16:34:19-05:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="Databases" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter-->
<p>If you are having trouble converting <a href="http://www.mysql.com/">MySQL</a> tables to <a href="http://sqlite.org">SQLite</a> tables then this tutorial is for you. On the other hand, if you have no idea what I just said then let me explain that both MySQL and SQLite are free, open source databases. While MySQL is the most used open source database in the world, SQLite is catching on as a great database for people who don't need a complex system to manage their data. I personally have been looking into it as a possibility for running my personal blog.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>If you are having trouble converting <a href="http://www.mysql.com/">MySQL</a> tables to <a href="http://sqlite.org">SQLite</a> tables then this tutorial is for you. On the other hand, if you have no idea what I just said then let me explain that both MySQL and SQLite are free, open source databases. While MySQL is the most used open source database in the world, SQLite is catching on as a great database for people who don't need a complex system to manage their data. I personally have been looking into it as a possibility for running my personal blog.</p>
<blockquote><p>SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file. The database file format is cross-platform - you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures. These features make SQLite a popular choice as an Application File Format. Think of SQLite not as a replacement for Oracle but as a replacement for fopen(). - the SQLite site
</p></blockquote>
<p>Anyway, if you have already started working with SQLite but have encountered problems with SQL syntax - I would like to explain some of the main differences in creating a table. Lets start with a basic MySQL table.</p>
<p><div class="codeblock"><code>/* Table structure for mySQL table */<br /><br />CREATE TABLE `tablename` (<br />    `id` int(11) NOT NULL auto_increment,<br />    `title` text NOT NULL default &#039;&#039;,<br />    `text` text NOT NULL,<br />    `time` int(10) NOT NULL default &#039;0000000000&#039;,<br />    UNIQUE KEY `id` (`id`),<br />) TYPE=MyISAM;</code></div></p>
<p>If you try to just port that over into SQLite - you'll get so many errors it's not funny. First lets start with the "INT" column type. In SQLite it is "INTEGER" not "INT". So, that is the first thing that needs to be changed.</p>
<p>Second, in SQLite "auto_increment" is a given if the key is a <b>PRIMARY KEY</b>. So we can delete the "auto_increment" part of the MySQL query. This now leaves us with the following:</p>
<p><div class="codeblock"><code>-- Table structure for NEW SQLite table<br />CREATE TABLE `tablename` (<br />    `id` INTEGER NOT NULL ,<br />    `title` text NOT NULL default &#039;&#039;,<br />    `text` text NOT NULL,<br />    `time` INTEGER NOT NULL default &#039;0000000000&#039;,<br />    UNIQUE KEY `id` (`id`),<br />) TYPE=MyISAM;</code></div></p>
<p>Third, we don't need the "<b>UNIQUE KEY `id` (`id`),</b>" line. In SQLite, that data goes on the same line as the item that is set to the "PRIMARY KEY".</p>
<p><div class="codeblock"><code>-- Table structure for NEW SQLite table<br />CREATE TABLE `tablename` (<br />    `id` INTEGER PRIMARY KEY NOT NULL ,<br />    `title` text NOT NULL default &#039;&#039;,<br />    `text` text NOT NULL,<br />    `time` INTEGER NOT NULL default &#039;0000000000&#039;,<br />) TYPE=MyISAM;</code></div></p>
<p>Forth, remove the bottom " TYPE=MyISAM" as there is no such type in SQLite. In MySQL you can chose from one of several DB types. However, SQLite only has 1 type - so there is no need to specify it.</p>
<p>Now the last thing we need to do is get rid of the " ` " characters in the code as SQLite doesn't like them in queries. So we just replace all the " ` " with double-quotes (NOT single quotes). You can also just leave them off as they are NOT required. Also, delete the ending comma. Our final output is:</p>
<p><div class="codeblock"><code>-- Table structure for NEW SQLite table<br />CREATE TABLE &quot;tablename&quot; (<br />    &quot;id&quot; INTEGER PRIMARY KEY NOT NULL ,<br />    &quot;title&quot; text NOT NULL default &quot;&quot;,<br />    &quot;text&quot; text NOT NULL,<br />    &quot;time&quot; INTEGER NOT NULL default &quot;0000000000&quot;<br />);</code></div></p>
<p>The following tables show how you can use double-quotes in any order without fear of trouble:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /><br />$query&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'CREATE&nbsp;TABLE&nbsp;temp2&nbsp;(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;NOT&nbsp;NULL,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time&nbsp;INTEGER&nbsp;NOT&nbsp;NULL<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br />CREATE&nbsp;TABLE&nbsp;"temp3"&nbsp;(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id"&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;NOT&nbsp;NULL,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "title"&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "text"&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "time"&nbsp;INTEGER&nbsp;NOT&nbsp;NULL<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br />CREATE&nbsp;TABLE&nbsp;temp4&nbsp;(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id"&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;NOT&nbsp;NULL,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "title"&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "text"&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "time"&nbsp;INTEGER&nbsp;NOT&nbsp;NULL<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br />CREATE&nbsp;TABLE&nbsp;temp5&nbsp;(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;NOT&nbsp;NULL,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "title"&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text&nbsp;TEXT&nbsp;NOT&nbsp;NULL&nbsp;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "time"&nbsp;INTEGER&nbsp;NOT&nbsp;NULL<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );'</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p><a href="http://sqlite.org/lang.html">SQL As Understood By SQLite</a> is a great read for anyone who wants to check advanced queries against the SQL standard. The <a href="http://www.sqlite.org/cvstrac/wiki?p=ManagementTools">SQLite Wiki</a> also has a great list of command-line &amp; desktop programs that you can use to create SQLite tables for you if you are still unsure about all this. I personally like <a href="http://sqliteman.com/">SQLiteMan</a> as I can create the database and tables right on my Windows desktop and then export a SQL Schema for use in my php scripts.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Members-system (using My-Sql)</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/members_system_using_my_sql" />
    <id>http://www.code2design.com/tutorial/members_system_using_my_sql</id>
    <published>2007-08-29T13:32:08-04:00</published>
    <updated>2008-01-17T15:28:59-05:00</updated>
    <author>
      <name>Alxandr</name>
    </author>
    <category term="Membership and User Authentication" />
    <summary type="html"><![CDATA[<h3>PHP and MySQL login-system</h3>
<p>Here I will teach you how to create a really basic login-system for use in php and mysql. The system can easily be built on to work with flash and other applications.<br />
I'll just start:<br />
First you need a "data.php" file that looks like this:<br />
<code>&lt;font color=&quot;#000000&quot;&gt;&lt;font color=&quot;#0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&amp;nbsp;&lt;br /&gt;$dbc&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_connect&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&quot;localhost&quot;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;,&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&quot;***username***&quot;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;,&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&quot;***password***&quot;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;);&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_select_db&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&quot;***db_name***&quot;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;);&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;session_start&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;();&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;?&amp;gt;&lt;/font&gt;&lt;/font&gt;</code><br />
You also need a database with a table (registered) with fields that look like the SQL code below. (If you want, you can copy it into phpMyAdmin and it will create the table.)<br />
<code>CREATE TABLE `registered` (&lt;br /&gt;  `id` int(11) NOT NULL auto_increment,&lt;br /&gt;  `username` varchar(64) NOT NULL,&lt;br /&gt;  `password` varchar(32) NOT NULL,&lt;br /&gt;  PRIMARY KEY  (`id`)&lt;br /&gt;) DEFAULT CHARSET=utf8;</code></p>
    ]]></summary>
    <content type="html"><![CDATA[<h3>PHP and MySQL login-system</h3>
<p>Here I will teach you how to create a really basic login-system for use in php and mysql. The system can easily be built on to work with flash and other applications.</p>
<p>I'll just start:</p>
<p>First you need a "data.php" file that looks like this:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp;<br />$dbc&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_connect</font><font color="#007700">(</font><font color="#DD0000">"localhost"</font><font color="#007700">,</font><font color="#DD0000">"***username***"</font><font color="#007700">,</font><font color="#DD0000">"***password***"</font><font color="#007700">);&nbsp;</font><font color="#0000BB">mysql_select_db</font><font color="#007700">(</font><font color="#DD0000">"***db_name***"</font><font color="#007700">);&nbsp;<br /></font><font color="#0000BB">session_start</font><font color="#007700">();<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>You also need a database with a table (registered) with fields that look like the SQL code below. (If you want, you can copy it into phpMyAdmin and it will create the table.)<br />
<div class="codeblock"><code>CREATE TABLE `registered` (<br />  `id` int(11) NOT NULL auto_increment,<br />  `username` varchar(64) NOT NULL,<br />  `password` varchar(32) NOT NULL,<br />  PRIMARY KEY  (`id`)<br />) DEFAULT CHARSET=utf8;</code></div></p>
<p>Then (in the main file) we need to include the "data.php"-file:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /></font><font color="#007700">include&nbsp;</font><font color="#DD0000">"data.php"</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /></font><font color="#007700">function&nbsp;</font><font color="#0000BB">loginForm</font><font color="#007700">(){<br /></font><font color="#0000BB">?&gt;</font></font></code></div><div class="codeblock"><code>&lt;form method=&quot;post&quot;&gt;<br />&lt;strong&gt;Username:&lt;/strong&gt; &lt;input type=&quot;text&quot; name=&quot;login[username]&quot; /&gt;&lt;br /&gt;<br />&lt;strong&gt;Password:&lt;/strong&gt; &lt;input type=&quot;password&quot; name=&quot;login[password]&quot; /&gt;&lt;br /&gt;<br />&lt;input type=&quot;submit&quot; /&gt;<br />&lt;/form&gt;</code></div><br />
<div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">}<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>Now what this does, is that if we ever run the function loginForm() it will output all that HTML there (which of course just is a basic form).</p>
<p>Then we need to make a is_logged_in() function. The code for that should be:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">function&nbsp;</font><font color="#0000BB">is_logged_in</font><font color="#007700">(){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#FF8000">//isset&nbsp;will&nbsp;return&nbsp;TRUE&nbsp;or&nbsp;FALSE<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#007700">return&nbsp;isset(</font><font color="#0000BB">$_SESSION</font><font color="#007700">[</font><font color="#DD0000">'loggedIn'</font><font color="#007700">]);<br />&nbsp; &nbsp; }<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>All this function does is to return whether or not the variable $_SESSION['loggedIn'] is set or not. If it is set - return true. If the session is NOT set - return false.</p>
<p>Now we need to make a function that tells us whether or not the user is trying to login.</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">function&nbsp;</font><font color="#0000BB">is_logging_in</font><font color="#007700">(){<br />&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;isset(</font><font color="#0000BB">$_POST</font><font color="#007700">[</font><font color="#DD0000">'login'</font><font color="#007700">]);<br />&nbsp; &nbsp; }<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>This will return true if the post-variable <span style="font-weight:bold">login</span> is set (remember, we put the input field inside an array named login... name="login[username]").</p>
<p>Now we need a function to do the login...</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">function&nbsp;</font><font color="#0000BB">login</font><font color="#007700">(</font><font color="#0000BB">$username</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$md5password</font><font color="#007700">){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$query&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'SELECT&nbsp;*&nbsp;FROM&nbsp;`registered`&nbsp;WHERE&nbsp;`username`&nbsp;=&nbsp;\''</font><font color="#007700">.</font><font color="#0000BB">mysql_real_escape_string</font><font color="#007700">(</font><font color="#0000BB">$username</font><font color="#007700">).&nbsp;</font><font color="#DD0000">'\'&nbsp;AND&nbsp;password&nbsp;=&nbsp;\''</font><font color="#007700">.&nbsp;</font><font color="#0000BB">mysql_real_escape_string</font><font color="#007700">(</font><font color="#0000BB">$md5password</font><font color="#007700">).&nbsp;</font><font color="#DD0000">'\''</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$rs&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_query</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">);<br />&nbsp; &nbsp; &nbsp; &nbsp; if(!</font><font color="#0000BB">mysql_num_rows</font><font color="#007700">(</font><font color="#0000BB">$rs</font><font color="#007700">)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo&nbsp;</font><font color="#DD0000">"&lt;strong&gt;Bad&nbsp;login!&lt;/strong&gt;&lt;br&nbsp;/&gt;"</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loginForm</font><font color="#007700">();&nbsp;</font><font color="#FF8000">//here&nbsp;we&nbsp;ask&nbsp;the&nbsp;user&nbsp;to&nbsp;login&nbsp;again...<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#007700">die();<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; while(</font><font color="#0000BB">$row&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$rs</font><font color="#007700">)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(</font><font color="#0000BB">$username&nbsp;</font><font color="#007700">==&nbsp;</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'username'</font><font color="#007700">]&nbsp;&amp;&amp;&nbsp;</font><font color="#0000BB">$md5password&nbsp;</font><font color="#007700">==&nbsp;</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'password'</font><font color="#007700">]){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$_SESSION</font><font color="#007700">[</font><font color="#DD0000">'loggedIn'</font><font color="#007700">]&nbsp;=&nbsp;</font><font color="#0000BB">true</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; die(</font><font color="#DD0000">"&lt;script&nbsp;language=\"javascript\"&gt;window.location.reload();&lt;/script&gt;"</font><font color="#007700">);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; echo&nbsp;</font><font color="#DD0000">"&lt;strong&gt;Bad&nbsp;login!&lt;/strong&gt;&lt;br&nbsp;/&gt;"</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loginForm</font><font color="#007700">();<br />&nbsp; &nbsp; &nbsp; &nbsp; die();<br />&nbsp; &nbsp; }<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>Than we need a function to deal with what to do is to create a function to manage what to happen if the user is logged in:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">function&nbsp;</font><font color="#0000BB">loggedIn</font><font color="#007700">(){<br />&nbsp; &nbsp; &nbsp; &nbsp; die(</font><font color="#DD0000">"&lt;h1&gt;You&nbsp;are&nbsp;logged&nbsp;in!&lt;/h1&gt;"</font><font color="#007700">);<br />&nbsp; &nbsp; }<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>Ok... Now we just need to structure everything out...</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">if(</font><font color="#0000BB">is_logged_in</font><font color="#007700">()){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loggedIn</font><font color="#007700">();<br />&nbsp; &nbsp; }&nbsp;elseif(</font><font color="#0000BB">is_logging_in</font><font color="#007700">()){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">login</font><font color="#007700">(</font><font color="#0000BB">$_POST</font><font color="#007700">[</font><font color="#DD0000">'login'</font><font color="#007700">][</font><font color="#DD0000">'username'</font><font color="#007700">],&nbsp;</font><font color="#0000BB">md5</font><font color="#007700">(</font><font color="#0000BB">$_POST</font><font color="#007700">[</font><font color="#DD0000">'login'</font><font color="#007700">][</font><font color="#DD0000">'password'</font><font color="#007700">]));<br />&nbsp; &nbsp; }&nbsp;else&nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loginForm</font><font color="#007700">();<br />&nbsp; &nbsp; }<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>All the code now looks like this:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">include&nbsp;</font><font color="#DD0000">"data.php"</font><font color="#007700">;<br />&nbsp; &nbsp; function&nbsp;</font><font color="#0000BB">loginForm</font><font color="#007700">(){<br /></font><font color="#0000BB">?&gt;</font></font></code></div><br />
<div class="codeblock"><code>&lt;form method=&quot;post&quot;&gt;<br />&lt;strong&gt;Username:&lt;/strong&gt; &lt;input type=&quot;text&quot; name=&quot;login[username]&quot; /&gt;&lt;br /&gt;<br />&lt;strong&gt;Password:&lt;/strong&gt; &lt;input type=&quot;password&quot; name=&quot;login[password]&quot; /&gt;&lt;br /&gt;<br />&lt;input type=&quot;submit&quot; /&gt;<br />&lt;/form&gt;</code></div><br />
<div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp; &nbsp; </font><font color="#007700">}<br />&nbsp; &nbsp; function&nbsp;</font><font color="#0000BB">is_logged_in</font><font color="#007700">(){<br />&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;isset(</font><font color="#0000BB">$_SESSION</font><font color="#007700">[</font><font color="#DD0000">'loggedIn'</font><font color="#007700">]);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; function&nbsp;</font><font color="#0000BB">is_logging_in</font><font color="#007700">(){<br />&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;isset(</font><font color="#0000BB">$_POST</font><font color="#007700">[</font><font color="#DD0000">'login'</font><font color="#007700">]);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; function&nbsp;</font><font color="#0000BB">login</font><font color="#007700">(</font><font color="#0000BB">$username</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$md5password</font><font color="#007700">){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$query&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'SELECT&nbsp;*&nbsp;FROM&nbsp;`registered`&nbsp;WHERE&nbsp;`username`&nbsp;=&nbsp;\''</font><font color="#007700">.</font><font color="#0000BB">mysql_real_escape_string</font><font color="#007700">(</font><font color="#0000BB">$username</font><font color="#007700">).&nbsp;</font><font color="#DD0000">'\'&nbsp;AND&nbsp;password&nbsp;=&nbsp;\''</font><font color="#007700">.&nbsp;</font><font color="#0000BB">mysql_real_escape_string</font><font color="#007700">(</font><font color="#0000BB">$md5password</font><font color="#007700">).&nbsp;</font><font color="#DD0000">'\''</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$rs&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_query</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">);<br />&nbsp; &nbsp; &nbsp; &nbsp; if(!</font><font color="#0000BB">mysql_num_rows</font><font color="#007700">(</font><font color="#0000BB">$rs</font><font color="#007700">)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo&nbsp;</font><font color="#DD0000">"&lt;strong&gt;Bad&nbsp;login!&lt;/strong&gt;&lt;br&nbsp;/&gt;"</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loginForm</font><font color="#007700">();&nbsp;</font><font color="#FF8000">//here&nbsp;we&nbsp;ask&nbsp;the&nbsp;user&nbsp;to&nbsp;login&nbsp;again...<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#007700">die();<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; while(</font><font color="#0000BB">$row&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$rs</font><font color="#007700">)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(</font><font color="#0000BB">$username&nbsp;</font><font color="#007700">==&nbsp;</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'username'</font><font color="#007700">]&nbsp;&amp;&amp;&nbsp;</font><font color="#0000BB">$md5password&nbsp;</font><font color="#007700">==&nbsp;</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'password'</font><font color="#007700">]){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">$_SESSION</font><font color="#007700">[</font><font color="#DD0000">'loggedIn'</font><font color="#007700">]&nbsp;=&nbsp;</font><font color="#0000BB">true</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; die(</font><font color="#DD0000">"&lt;script&nbsp;language=\"javascript\"&gt;window.location.reload();&lt;/script&gt;"</font><font color="#007700">);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; echo&nbsp;</font><font color="#DD0000">"&lt;strong&gt;Bad&nbsp;login!&lt;/strong&gt;&lt;br&nbsp;/&gt;"</font><font color="#007700">;<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loginForm</font><font color="#007700">();<br />&nbsp; &nbsp; &nbsp; &nbsp; die();<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; function&nbsp;</font><font color="#0000BB">loggedIn</font><font color="#007700">(){<br />&nbsp; &nbsp; &nbsp; &nbsp; die(</font><font color="#DD0000">"&lt;h1&gt;You&nbsp;are&nbsp;loged&nbsp;in!&lt;/h1&gt;"</font><font color="#007700">);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; </font><font color="#FF8000">//here&nbsp;komes&nbsp;the&nbsp;logic...<br />&nbsp; &nbsp; </font><font color="#007700">if(</font><font color="#0000BB">is_logged_in</font><font color="#007700">()){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loggedIn</font><font color="#007700">();<br />&nbsp; &nbsp; }&nbsp;elseif(</font><font color="#0000BB">is_logging_in</font><font color="#007700">()){<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">login</font><font color="#007700">(</font><font color="#0000BB">$_POST</font><font color="#007700">[</font><font color="#DD0000">'login'</font><font color="#007700">][</font><font color="#DD0000">'username'</font><font color="#007700">],&nbsp;</font><font color="#0000BB">md5</font><font color="#007700">(</font><font color="#0000BB">$_POST</font><font color="#007700">[</font><font color="#DD0000">'login'</font><font color="#007700">][</font><font color="#DD0000">'password'</font><font color="#007700">]));<br />&nbsp; &nbsp; }&nbsp;else&nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000BB">loginForm</font><font color="#007700">();<br />&nbsp; &nbsp; }<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
    ]]></content>
  </entry>
  <entry>
    <title>Javascript tooltips</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/javascript_tooltips" />
    <id>http://www.code2design.com/tutorial/javascript_tooltips</id>
    <published>2007-06-02T13:51:51-04:00</published>
    <updated>2007-06-09T12:51:19-04:00</updated>
    <author>
      <name>Alxandr</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter--><br />
<h4>Easy tooltips using javascript and html</h4>
<style>
<!--
body { background-color: #ffffff; color: #000000; }
pre { font-family: "Courier New",Courier,monospace; font-size: 12px; color: #000000; }
span.comment { color: #777777; font-weight: normal; }
span.oper { color: #8d7f07; font-weight: bold; }
span.var { color: #008080; font-weight: normal; }
span.func { color: #aa00ff; font-weight: bold; }
span.string { color: #990000; font-weight: normal; }
span.num { color: #990000; font-weight: bold; }
span.reg { color: #990000; font-weight: normal; }
-->
</style><p>Today I'm gone teach you how to create tooltips in HTML. First of all, you need to let the computer know that we are writing javascript - So start by typing:</p>
<div class="codeblock"><code>&amp;lt;script language=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/script&amp;gt;;</code></div>
</p>
<p>Now that we have the container for the javascript we can now add the actual code for the tooltips. Paste this inside the script tags:</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><h4>Easy tooltips using javascript and html</h4>
<style>
<!--
body { background-color: #ffffff; color: #000000; }
pre { font-family: "Courier New",Courier,monospace; font-size: 12px; color: #000000; }
span.comment { color: #777777; font-weight: normal; }
span.oper { color: #8d7f07; font-weight: bold; }
span.var { color: #008080; font-weight: normal; }
span.func { color: #aa00ff; font-weight: bold; }
span.string { color: #990000; font-weight: normal; }
span.num { color: #990000; font-weight: bold; }
span.reg { color: #990000; font-weight: normal; }
-->
</style><p>Today I'm gone teach you how to create tooltips in HTML. First of all, you need to let the computer know that we are writing javascript - So start by typing:<br />
<div class="codeblock"><code>&lt;script language=&quot;javascript&quot;&gt;<br /><br />&lt;/script&gt;;</code></div></p>
<p>Now that we have the container for the javascript we can now add the actual code for the tooltips. Paste this inside the script tags:</p>
<pre><span class="oper">var</span> <span class="var">ns4</span> <span class="oper">=</span> <span class="var">document</span>.<span class="var">layers</span>;
<span class="oper">var</span> <span class="var">ns6</span> <span class="oper">=</span> <span class="var">document</span>.<span class="var">getElementById</span> <span class="oper">&amp;</span><span class="oper">&amp;</span> <span class="oper">!</span><span class="var">document</span>.<span class="var">all</span>;
<span class="oper">var</span> <span class="var">ie4</span> <span class="oper">=</span> <span class="var">document</span>.<span class="var">all</span>;
<span class="var">offsetX</span> <span class="oper">=</span> <span class="num">05</span>;
<span class="var">offsetY</span> <span class="oper">=</span> <span class="num">20</span>;
<span class="oper">var</span> <span class="var">toolTipSTYLE</span> <span class="oper">=</span> &quot;<span class="string"></span>&quot;;
<span class="oper">function</span> <span class="func">initToolTips</span>() {
	<span class="oper">var</span> <span class="var">ttarea</span> <span class="oper">=</span> <span class="var">document</span>.<span class="func">createElement</span>('<span class="string">div</span>');
	<span class="var">ttarea</span>.<span class="func">setAttribute</span>('<span class="string">id</span>','<span class="string">toolTipLayer</span>');
	<span class="var">ttarea</span>.<span class="var">style</span>.<span class="var">position</span> <span class="oper">=</span> &quot;<span class="string">absolute</span>&quot;;
	<span class="var">ttarea</span>.<span class="var">style</span>.<span class="var">width</span> <span class="oper">=</span> &quot;<span class="string">250px</span>&quot;;
	<span class="oper">if</span>(<span class="var">document</span>.<span class="var">appendChild</span>){
		<span class="var">document</span>.<span class="var">body</span>.<span class="func">appendChild</span>(<span class="var">ttarea</span>);
	} <span class="oper">else</span> {
		<span class="func">alert</span>(&quot;<span class="string">Your browser does not support the script used at this page, pleas switch browser</span>&quot;);	
	}
	<span class="oper">if</span>(<span class="var">ns4</span><span class="oper">|</span><span class="oper">|</span><span class="var">ns6</span><span class="oper">|</span><span class="oper">|</span><span class="var">ie4</span>) {
		<span class="oper">if</span>(<span class="var">ns4</span>) {
			<span class="var">toolTipSTYLE</span> <span class="oper">=</span> <span class="var">document</span>.<span class="var">toolTipLayer</span>;
		} <span class="oper">else</span> <span class="oper">if</span>(<span class="var">ns6</span>) {
			<span class="var">toolTipSTYLE</span> <span class="oper">=</span> <span class="var">document</span>.<span class="func">getElementById</span>(&quot;<span class="string">toolTipLayer</span>&quot;).<span class="var">style</span>;
		} <span class="oper">else</span> <span class="oper">if</span>(<span class="var">ie4</span>) {
			<span class="var">toolTipSTYLE</span> <span class="oper">=</span> <span class="var">document</span>.<span class="var">all</span>.<span class="var">toolTipLayer</span>.<span class="var">style</span>;
		}
		<span class="oper">if</span>(<span class="var">ns4</span>) {
			<span class="var">document</span>.<span class="func">captureEvents</span>(<span class="var">Event</span>.<span class="var">MOUSEMOVE</span>);
		} <span class="oper">else</span> {
			<span class="var">toolTipSTYLE</span>.<span class="var">visibility</span> <span class="oper">=</span> &quot;<span class="string">visible</span>&quot;;
			<span class="var">toolTipSTYLE</span>.<span class="var">display</span> <span class="oper">=</span> &quot;<span class="string">none</span>&quot;;
		}
		<span class="var">document</span>.<span class="var">onmousemove</span> <span class="oper">=</span> <span class="var">moveToMouseLoc</span>;
	}
}
<span class="oper">function</span> <span class="func">toolTip</span>(<span class="var">msg</span>, <span class="var">fg</span>, <span class="var">bg</span>, <span class="var">border</span>)
{
	<span class="oper">if</span>(<span class="var">toolTip</span>.<span class="var">arguments</span>.<span class="var">length</span> <span class="oper">&lt;</span> <span class="num">1</span>) {
		<span class="oper">if</span>(<span class="var">ns4</span>) {
			<span class="var">toolTipSTYLE</span>.<span class="var">visibility</span> <span class="oper">=</span> &quot;<span class="string">hidden</span>&quot;;
		} <span class="oper">else</span> {
			<span class="var">toolTipSTYLE</span>.<span class="var">display</span> <span class="oper">=</span> &quot;<span class="string">none</span>&quot;;
		}
	} <span class="oper">else</span> {
		<span class="oper">if</span>(<span class="oper">!</span><span class="var">fg</span>) {
			<span class="var">fg</span> <span class="oper">=</span> &quot;<span class="string">#777777</span>&quot;;
		}
		<span class="oper">if</span>(<span class="oper">!</span><span class="var">bg</span>) {
			<span class="var">bg</span> <span class="oper">=</span> &quot;<span class="string">#FFFFFF</span>&quot;;
		}
		<span class="oper">if</span>(<span class="oper">!</span><span class="var">border</span>){
			<span class="var">border</span> <span class="oper">=</span> <span class="var">fg</span>;	
		}
		<span class="oper">var</span> <span class="var">content</span> <span class="oper">=</span> '<span class="string">&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;1&quot; bgcolor=&quot;</span>';
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> <span class="var">border</span>;
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> '<span class="string">&quot;&gt;&lt;td&gt;</span>';
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> '<span class="string">&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;1&quot; bgcolor=&quot;</span>';
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> <span class="var">bg</span>;
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> '<span class="string">&quot;&gt;&lt;td align=&quot;center&quot;&gt;&lt;font face=&quot;sans-serif&quot; color=&quot;</span>';
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> <span class="var">fg</span>;
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> '<span class="string">&quot; size=&quot;-2&quot;&gt;&amp;nbsp\;</span>';
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> <span class="var">msg</span>;
		<span class="var">content</span> <span class="oper">+</span><span class="oper">=</span> '<span class="string">&amp;nbsp\;&lt;/font&gt;&lt;/td&gt;&lt;/table&gt;&lt;/td&gt;&lt;/table&gt;</span>';
		<span class="oper">if</span>(<span class="var">ns4</span>) {
			<span class="var">toolTipSTYLE</span>.<span class="var">document</span>.<span class="func">write</span>(<span class="var">content</span>);
			<span class="var">toolTipSTYLE</span>.<span class="var">document</span>.<span class="func">close</span>();
			<span class="var">toolTipSTYLE</span>.<span class="var">visibility</span> <span class="oper">=</span> &quot;<span class="string">visible</span>&quot;;
		}
		<span class="oper">if</span>(<span class="var">ns6</span>) {
			<span class="var">document</span>.<span class="func">getElementById</span>(&quot;<span class="string">toolTipLayer</span>&quot;).<span class="var">innerHTML</span> <span class="oper">=</span> <span class="var">content</span>;
			<span class="var">toolTipSTYLE</span>.<span class="var">display</span> <span class="oper">=</span> '<span class="string">block</span>';
		}
		<span class="oper">if</span>(<span class="var">ie4</span>) {
			<span class="var">document</span>.<span class="func">all</span>(&quot;<span class="string">toolTipLayer</span>&quot;).<span class="var">innerHTML</span><span class="oper">=</span><span class="var">content</span>;
			<span class="var">toolTipSTYLE</span>.<span class="var">display</span><span class="oper">=</span>'<span class="string">block</span>';
		}
	}
}
<span class="oper">function</span> <span class="func">moveToMouseLoc</span>(<span class="var">e</span>) {
	<span class="oper">if</span>(<span class="var">ns4</span><span class="oper">|</span><span class="oper">|</span><span class="var">ns6</span>) {
		<span class="var">x</span> <span class="oper">=</span> <span class="var">e</span>.<span class="var">pageX</span>;
		<span class="var">y</span> <span class="oper">=</span> <span class="var">e</span>.<span class="var">pageY</span>;
	} <span class="oper">else</span> {
		<span class="var">x</span> <span class="oper">=</span> <span class="var">event</span>.<span class="var">x</span> <span class="oper">+</span> <span class="var">document</span>.<span class="var">body</span>.<span class="var">scrollLeft</span>;
		<span class="var">y</span> <span class="oper">=</span> <span class="var">event</span>.<span class="var">y</span> <span class="oper">+</span> <span class="var">document</span>.<span class="var">body</span>.<span class="var">scrollTop</span>;
	}
	<span class="var">toolTipSTYLE</span>.<span class="var">left</span> <span class="oper">=</span> <span class="var">x</span> <span class="oper">+</span> <span class="var">offsetX</span>;
	<span class="var">toolTipSTYLE</span>.<span class="var">top</span> <span class="oper">=</span> <span class="var">y</span> <span class="oper">+</span> <span class="var">offsetY</span>;
	<span class="oper">return</span> <span class="num">true</span>;
}
<span class="oper">function</span> <span class="func">setToolTip</span>(<span class="var">object</span>, <span class="var">msg</span>, <span class="var">fg</span>, <span class="var">bg</span>, <span class="var">border</span>){
	<span class="oper">if</span>(<span class="var">setToolTip</span>.<span class="var">arguments</span>.<span class="var">length</span> <span class="oper">&lt;</span> <span class="num">2</span>) {
		<span class="oper">return</span> <span class="num">false</span>;
	} <span class="oper">else</span> {
		<span class="oper">switch</span> (<span class="var">setToolTip</span>.<span class="var">arguments</span>.<span class="var">length</span>) {
			<span class="oper">case</span> <span class="num">2</span><span class="oper">:</span>
				<span class="var">object</span>.<span class="var">onmouseover</span> <span class="oper">=</span> <span class="oper">function</span>(){
					<span class="func">toolTip</span>(<span class="var">msg</span>);	
				}
				<span class="oper">break</span>;
			<span class="oper">case</span> <span class="num">3</span><span class="oper">:</span>
				<span class="var">object</span>.<span class="var">onmouseover</span> <span class="oper">=</span> <span class="oper">function</span>(){
					<span class="func">toolTip</span>(<span class="var">msg</span>, <span class="var">fg</span>);	
				}
				<span class="oper">break</span>;
			<span class="oper">case</span> <span class="num">4</span><span class="oper">:</span>
				<span class="var">object</span>.<span class="var">onmouseover</span> <span class="oper">=</span> <span class="oper">function</span>(){
					<span class="func">toolTip</span>(<span class="var">msg</span>, <span class="var">fg</span>, <span class="var">bg</span>);	
				}
				<span class="oper">break</span>;
			<span class="oper">case</span> <span class="num">5</span><span class="oper">:</span>
				<span class="var">object</span>.<span class="var">onmouseover</span> <span class="oper">=</span> <span class="oper">function</span>(){
					<span class="func">toolTip</span>(<span class="var">msg</span>, <span class="var">fg</span>, <span class="var">bg</span>, <span class="var">border</span>);	
				}
				<span class="oper">break</span>;
			<span class="oper">default</span><span class="oper">:</span>
				<span class="var">object</span>.<span class="var">onmouseover</span> <span class="oper">=</span> <span class="oper">function</span>(){
					<span class="func">toolTip</span>(<span class="var">msg</span>, <span class="var">fg</span>, <span class="var">bg</span>);	
				}
				<span class="oper">break</span>;
		}
		<span class="var">object</span>.<span class="var">onmouseout</span> <span class="oper">=</span> <span class="oper">function</span>(){
			<span class="func">toolTip</span>();	
		}
	}
}
<span class="func">initToolTips</span>();</pre><p>
Don't bother trying to understand everything that happens, even I don't... But what is importent now is that to create a tooltip to a spessific object you can use one out of two methods... The first one is to add this attributes to a already existing html-tag: <div class="codeblock"><code>onmouseover=&quot;tooltip(&#039;text&#039;,&#039;#forgroundcollor&#039;,&#039;#backgroundcolor&#039;,&#039;#bordercolor&#039;);&quot; onmouseout=&quot;tooltip();&quot;</code></div><br />
Now of couse this won't work because #forgrondcollor isn't a valid collor, you need to use valid collors for every field that starts with an '#'. Aditionaly you only need to add one parameter, then the code looks like this:<br />
<div class="codeblock"><code>onmouseover=&quot;tooltip(&#039;text&#039;);&quot; onmouseout=&quot;tooltip();&quot;</code></div><br />
The second method is to add id to every element that you wan't to create a tooltip belonging to and then at the very bottom of the page (just before the closing &lt;body&gt; tag you can add this script: </p>
<pre>
&lt;script language="javascript"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;<span class="func">setToolTip</span>(<span class="var">document</span>.<span class="func">getElementById</span>(&quot;<span class="string">theId</span>&quot;), &quot;<span class="string">text</span>&quot;);
&lt;/script&gt; </pre><p>
And that's it, you're done!</p>
    ]]></content>
  </entry>
  <entry>
    <title>SELECT COUNT from database</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/select_count_from_database" />
    <id>http://www.code2design.com/tutorial/select_count_from_database</id>
    <published>2007-05-13T20:16:42-04:00</published>
    <updated>2007-05-13T20:17:15-04:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="Databases" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter-->
<p>I thought I would just take a minute to share this little code snippet with you as I had some trouble finding posts online that would tell me if I was going about this the right way! The problem is that I needed a fast way to <span style="font-weight:bold">count how many rows were in a database</span> without using a CPU demanding function like <a href="http://php.net/mysql_num_rows">mysql_num_rows()</a>.</p>
<p>
<div class="codeblock"><code>&lt;font color=&quot;#000000&quot;&gt;&lt;font color=&quot;#0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$query&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&#039;SELECT&amp;nbsp;COUNT(*)&amp;nbsp;FROM&amp;nbsp;`users`&#039;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$result&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_query&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$query&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;)&amp;nbsp;or&amp;nbsp;die(&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&#039;Sorry,&amp;nbsp;we&amp;nbsp;could&amp;nbsp;not&amp;nbsp;count&amp;nbsp;the&amp;nbsp;number&amp;nbsp;of&amp;nbsp;results:&amp;nbsp;&#039;&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;.&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_error&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;());&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$numberofresults&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_result&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$result&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;0&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;);&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;?&amp;gt;&lt;/font&gt;&lt;/font&gt;</code></div>
</p>
<p>You can also limit the count to only rows that meet a certain value:</p>
<div class="codeblock"><code>&lt;font color=&quot;#000000&quot;&gt;&lt;font color=&quot;#0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#FF8000&quot;&gt;//Where&amp;nbsp;the&amp;nbsp;user&amp;nbsp;id&amp;nbsp;is&amp;nbsp;greater&amp;nbsp;than&amp;nbsp;149.&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$query&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&#039;SELECT&amp;nbsp;COUNT(*)&amp;nbsp;FROM&amp;nbsp;`your_table`&amp;nbsp;WHERE&amp;nbsp;`id`&amp;nbsp;&amp;gt;&amp;nbsp;149&#039;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$result&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_query&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$query&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;)&amp;nbsp;or&amp;nbsp;die(&lt;/font&gt;&lt;font color=&quot;#DD0000&quot;&gt;&#039;Sorry,&amp;nbsp;we&amp;nbsp;could&amp;nbsp;not&amp;nbsp;count&amp;nbsp;the&amp;nbsp;number&amp;nbsp;of&amp;nbsp;results:&amp;nbsp;&#039;&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;.&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_error&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;());&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$numberofresults&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;mysql_result&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;$result&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;0&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;);&lt;br /&gt;&lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;?&amp;gt;&lt;/font&gt;&lt;/font&gt;</code></div>
</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>I thought I would just take a minute to share this little code snippet with you as I had some trouble finding posts online that would tell me if I was going about this the right way! The problem is that I needed a fast way to <span style="font-weight:bold">count how many rows were in a database</span> without using a CPU demanding function like <a href="http://php.net/mysql_num_rows">mysql_num_rows()</a>.</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />$query&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'SELECT&nbsp;COUNT(*)&nbsp;FROM&nbsp;`users`'</font><font color="#007700">;<br /></font><font color="#0000BB">$result&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_query</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">)&nbsp;or&nbsp;die(</font><font color="#DD0000">'Sorry,&nbsp;we&nbsp;could&nbsp;not&nbsp;count&nbsp;the&nbsp;number&nbsp;of&nbsp;results:&nbsp;'&nbsp;</font><font color="#007700">.&nbsp;</font><font color="#0000BB">mysql_error</font><font color="#007700">());<br /></font><font color="#0000BB">$numberofresults&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_result</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">,&nbsp;</font><font color="#0000BB">0</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>You can also limit the count to only rows that meet a certain value:<br />
<div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">//Where&nbsp;the&nbsp;user&nbsp;id&nbsp;is&nbsp;greater&nbsp;than&nbsp;149.<br /></font><font color="#0000BB">$query&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#DD0000">'SELECT&nbsp;COUNT(*)&nbsp;FROM&nbsp;`your_table`&nbsp;WHERE&nbsp;`id`&nbsp;&gt;&nbsp;149'</font><font color="#007700">;<br /></font><font color="#0000BB">$result&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_query</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">)&nbsp;or&nbsp;die(</font><font color="#DD0000">'Sorry,&nbsp;we&nbsp;could&nbsp;not&nbsp;count&nbsp;the&nbsp;number&nbsp;of&nbsp;results:&nbsp;'&nbsp;</font><font color="#007700">.&nbsp;</font><font color="#0000BB">mysql_error</font><font color="#007700">());<br /></font><font color="#0000BB">$numberofresults&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">mysql_result</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">,&nbsp;</font><font color="#0000BB">0</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>Keep in mind that this is for counting all the <span style="font-weight:bold">rows</span> in the table. For example, if you had a database like this with 40 of your "users" in it:<br />
<div class="codeblock"><code>CREATE TABLE `users` (<br />  `id` int(11) NOT NULL auto_increment,<br />  `username` varchar(20) NOT NULL default &#039;&#039;,<br />  `password` varchar(20) NOT NULL default &#039;&#039;,<br />  `email` varchar(70) NOT NULL default &#039;&#039;,<br />)</code></div><br />
Even though there are 4 fields in each members row - the result of the above script will only output "<span style="font-weight:bold">40</span>" not "160". Because while there are a total of 160 columns in all - there are only 40 users (each with the above four columns in their row).</p>
<p>Remember, it is slower to select a single field (<span style="font-weight:bold">SELECT COUNT(id)FROM `users`</span>) than it is to just count the whole thing (<span style="font-weight:bold">SELECT COUNT(*)FROM `users`</span>). Because MySQL already knows how many rows are in each database - so it can just tell you. But if you specify a certain field - then MySQL has to open each row and look around for that field.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Free AutoDesk Inventor</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/david/free_autodesk_inventor" />
    <id>http://www.code2design.com/david/free_autodesk_inventor</id>
    <published>2007-04-19T18:05:08-04:00</published>
    <updated>2007-04-19T18:05:08-04:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="AutoCAD" />
    <category term="Site News" />
    <summary type="html"><![CDATA[<p><a href="http://autodesk.com/">AutoDesk</a> is giving away free copies of its student programs like <a href="http://usa.autodesk.com/adsk/servlet/index?siteID=123112&amp;id=4246282">AutoDesk Inventor</a>. If you are a student you need to take a minute to register for this great offer! (visit <a href="http://students3.autodesk.com/">Student Autodesk</a>)<br />
As soon as my month-long fight with my computer-box is over (Curse you SATA, Cheap Video Cards, and ECS Mobos), I plan on releasing some Inventor tutorials and because it is a $4000 program (Full Version) this maybe your only chance to grab a copy!<br />
Please note that you must be a student with a college email address(I think they also allow Highschool emails). Also, you will need a decent video card for this program as it is a 3D modeling program. (64MB video card should be fine - but I suggest a 128MB.)</p>
    ]]></summary>
    <content type="html"><![CDATA[<p><a href="http://autodesk.com/">AutoDesk</a> is giving away <span style="font-weight:bold">free copies</span> of its student programs like <a href="http://usa.autodesk.com/adsk/servlet/index?siteID=123112&amp;id=4246282">AutoDesk Inventor</a>. If you are a student you <span style="font-style:italic">need</span> to take a minute to register for this great offer! (visit <a href="http://students3.autodesk.com/">Student Autodesk</a>) </p>
<p>As soon as my month-long fight with my computer-box is over (Curse you SATA, Cheap Video Cards, and ECS Mobos), I plan on releasing some Inventor tutorials and because it is a $4000 program (Full Version) this maybe your only chance to grab a copy! </p>
<p>Please note that you must be a student with a college email address(I think they also allow Highschool emails). Also, you will need a decent video card for this program as it is a 3D modeling program. (64MB video card should be fine - but I suggest a 128MB.)</p>
    ]]></content>
  </entry>
  <entry>
    <title>Simple 3 Column</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/simple_3_column" />
    <id>http://www.code2design.com/simple_3_column</id>
    <published>2007-04-17T21:13:57-04:00</published>
    <updated>2007-04-17T23:47:41-04:00</updated>
    <author>
      <name>David</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter-->
<p>After traveling around looking at sites that hurt my eyes I thought I would put together a basic template that is good-looking, XHTML valid with 3-Columns, and yet simple enough that you can easily navigate the page.</p>
<p>So here is a Cross-Browser compatible design that I have tested in IE6 &amp; 7, Firefox 2, and Opera 9. You can see it live here: <a href="http://webn.ws/simple3column/" target="_blank">Simple 3 Column</a></p>
<p>Now, the point of this design isn't necessarily for you to just have something through up on your site - but for you to have a basic design to work off of and to hack into your own custom creation. That is why I have included <span style="font-weight:bold">TWO</span> style sheets with this theme. The default is "pretty.css" but if you plan on using the layout as a basis for your own design I recommend you open "index.html" and change the style sheet from "pretty.css" to "simple.css". Because the simple style sheet is cleaner and easy to follow for those changing things...</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>After traveling around looking at sites that hurt my eyes I thought I would put together a basic template that is good-looking, XHTML valid with 3-Columns, and yet simple enough that you can easily navigate the page.</p>
<p>So here is a Cross-Browser compatible design that I have tested in IE6 &amp; 7, Firefox 2, and Opera 9. You can see it live here: <a href="http://webn.ws/simple3column/" target="_blank">Simple 3 Column</a></p>
<p>Now, the point of this design isn't necessarily for you to just have something through up on your site - but for you to have a basic design to work off of and to hack into your own custom creation. That is why I have included <span style="font-weight:bold">TWO</span> style sheets with this theme. The default is "pretty.css" but if you plan on using the layout as a basis for your own design I recommend you open "index.html" and change the style sheet from "pretty.css" to "simple.css". Because the simple style sheet is cleaner and easy to follow for those changing things...</p>
<p>Remember, keep the content area clean, white, and simple - there <span style="font-weight:bold">is</span> a reason the top websites do it this way. ;)</p>
<p>If you want to change the width of the layout check out <a href="http://code2design.com/understanding_css_dimensions">this post on dimensions</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Understanding CSS Dimensions</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/understanding_css_dimensions" />
    <id>http://www.code2design.com/tutorial/understanding_css_dimensions</id>
    <published>2007-04-17T15:24:35-04:00</published>
    <updated>2007-04-17T23:06:36-04:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="Dimensions" />
    <category term="Padding" />
    <summary type="html"><![CDATA[<p>If you have ever taken a dive into the CSS code of a layout you liked - only to find something like this:<br />
<code>.object {&lt;br /&gt;    margin: 0px auto 20px .8%;&lt;br /&gt;    padding: 0em 25px;&lt;br /&gt;}</code><br />
Then this tutorial is for you - because today I am going to explain the strange dimension system built into CSS! :)<br />
Now first off, how many of you have ever be at a lost as to the direction you were going? Or have to think for a minute to figure out where West is from North? Even more to the point - how many of you have ever heard the old saying "Never Eat Soggy Waffles"? (No, quite that! - I didn't make it up!) Well, for all us humans without GPS systems - this saying stands for "North East South West" which is the clock-wise order of the directions.<br />
<code>---N---&lt;br /&gt;W-----E&lt;br /&gt;---S---</code><br />
Well, CSS also uses the clockwise order of directions. Take a look at the following code:<br />
When you see something like:<br />
<code>.object {&lt;br /&gt;    padding: 10px 25px 5px 0px;&lt;br /&gt;}</code></p>
    ]]></summary>
    <content type="html"><![CDATA[<p>If you have ever taken a dive into the CSS code of a layout you liked - only to find something like this:<br />
<div class="codeblock"><code>.object {<br />    margin: 0px auto 20px .8%;<br />    padding: 0em 25px;<br />}</code></div><br />
Then this tutorial is for you - because today I am going to explain the strange dimension system built into CSS! :)</p>
<p>Now first off, how many of you have ever be at a lost as to the direction you were going? Or have to think for a minute to figure out where West is from North? Even more to the point - how many of you have ever heard the old saying "Never Eat Soggy Waffles"? (No, quite that! - I didn't make it up!) Well, for all us humans without GPS systems - this saying stands for "North East South West" which is the clock-wise order of the directions.<br />
<div class="codeblock"><code>---N---<br />W-----E<br />---S---</code></div><br />
Well, CSS also uses the clockwise order of directions. Take a look at the following code:</p>
<p>When you see something like:<br />
<div class="codeblock"><code>.object {<br />    padding: 10px 25px 5px 0px;<br />}</code></div><br />
If it were in English it would say:<br />
<div class="codeblock"><code>.object {<br />padding (is): 10pixels(top) 25pixels(right) 5pixels(bottom) 0pixels(on left);<br />}<br />.object {<br />padding (is): 10pixels(North) 25pixels(East) 5pixels(South) 0pixels(West);<br />}</code></div></p>
<p>So just remember that the first element is the top (North) dimension and the rest can be found be saying "Never Eat Soggy Waffles". Now, CSS also has built in pattern recognizers. For instance look at the following code that only seems to cover the padding for the top and right of ".object".<br />
<div class="codeblock"><code>.object {<br />    padding: 10px 25px;<br />}</code></div><br />
So what is the padding for the left and bottom of ".object"? Well, it is 10pixels on the bottom and 25pixels on the left. The computer automatically assumes that if you don't enter all the dimensions it should just keep repeating the pattern to fill in the remaining spaces. So to the computer, the above code would look like this:<br />
<div class="codeblock"><code>.object {<br />    padding: 10px 25px (10px 25px);<br />}</code></div><br />
Just like you can type the first three values of a HEX number "color: #fff;" (white) and the computer will recognize it as the full 6 digit HEX number "color: #ffffff;" (white) - you can also type "padding: 5px 10px;" and the computer will see it as "padding: 5px 10px 5px 10px;". The computer will even read just one value and fill all remaining values with that number!<br />
<div class="codeblock"><code>.object {<br />    padding: 10px;<br />}<br />Would mean this to the computer:<br />.object {<br />    padding: 10px (10px 10px 10px);<br />}</code></div></p>
<p>So, hopefully you can use this tutorial to help you better follow the code of CSS champs. :)</p>
    ]]></content>
  </entry>
  <entry>
    <title>Instant HTML Help</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/warpnacelle/instant_html_help" />
    <id>http://www.code2design.com/warpnacelle/instant_html_help</id>
    <published>2007-04-14T01:19:41-04:00</published>
    <updated>2007-04-14T01:19:41-04:00</updated>
    <author>
      <name>WarpNacelle</name>
    </author>
    <category term="HTML" />
    <category term="Tools" />
    <summary type="html"><![CDATA[<p>If you're just learning how to create your own little space in the vast expanse of the World Wide Web you are starting at a great time.<br />
When I began learning, nearly 10 years ago, I had to crack open the books, fire up Wordpad and figure this stuff out by trial and error.  If I needed help, it was a long search through various indexes.<br />
Now, there are so many resources on the web that anyone wanting to learn HTML or any of the vast languages out there, they have gold readily available at the click of a mouse.  Plus, with Web 2.0 becoming more and more prevalent, instant examples are here.<br />
Case in point is the HTML Playground: <a href="http://htmlplayground.com/"><a href="http://htmlplayground.com/">http://htmlplayground.com/</a></a><br />
The name says it all.  A list of web coding tags are available for you to select and have instant examples and sample code to look at and then edit it and see what happens.<br />
This is a fantastic resource for any beginner and one I highly recommend checking out and, well, playing around with!</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>If you're just learning how to create your own little space in the vast expanse of the World Wide Web you are starting at a great time.</p>
<p>When I began learning, nearly 10 years ago, I had to crack open the books, fire up Wordpad and figure this stuff out by trial and error.  If I needed help, it was a long search through various indexes.</p>
<p>Now, there are so many resources on the web that anyone wanting to learn HTML or any of the vast languages out there, they have gold readily available at the click of a mouse.  Plus, with Web 2.0 becoming more and more prevalent, instant examples are here.</p>
<p>Case in point is the HTML Playground: <a href="http://htmlplayground.com/">http://htmlplayground.com/</a></p>
<p>The name says it all.  A list of web coding tags are available for you to select and have instant examples and sample code to look at and then edit it and see what happens.</p>
<p>This is a fantastic resource for any beginner and one I highly recommend checking out and, well, playing around with!</p>
    ]]></content>
  </entry>
  <entry>
    <title>You Can CMS Without One Two</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/maspick/you_can_cms_without_one_two" />
    <id>http://www.code2design.com/maspick/you_can_cms_without_one_two</id>
    <published>2007-04-05T16:07:03-04:00</published>
    <updated>2007-04-05T16:17:50-04:00</updated>
    <author>
      <name>maspick</name>
    </author>
    <category term="Maspick" />
    <category term="PHP" />
    <summary type="html"><![CDATA[<p>In my last posting, I demonstrated how to create a header and footer file to be included at the top and bottom of all, or at least many, pages.  This makes it easy to modify those parts and have the changes automatically spread across all the pages that share that header and footer file.  This is one of the things a CMS simplifies for the user.<br />
But what if part of your header, or footer, file is your navigation system and you want the button or link to change when the page associated is chosen?  That means your header, or footer, must change depending on what page it's included on.  Actually, that's one of the beautiful things about PHP - since it's commands are processed prior to the display of the page, you can program those changes to happen for you automatically.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>In my last posting, I demonstrated how to create a header and footer file to be included at the top and bottom of all, or at least many, pages.  This makes it easy to modify those parts and have the changes automatically spread across all the pages that share that header and footer file.  This is one of the things a CMS simplifies for the user.</p>
<p>But what if part of your header, or footer, file is your navigation system and you want the button or link to change when the page associated is chosen?  That means your header, or footer, must <span style="font-style:italic">change</span> depending on what page it's included on.  Actually, that's one of the beautiful things about PHP - since it's commands are processed prior to the display of the page, you can <span style="font-style:italic">program</span> those changes to happen for you automatically.</p>
<p>The first thing we need to do is determine what page is being displayed at the moment.  The following bit of code, placed at the top of your header file so that it's executed first, will get you the page you're on:</p>
<p><div class="codeblock"><code><font color="#000000"><font color="#0000BB">&lt;?php<br />$parts&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">'/'</font><font color="#007700">,&nbsp;</font><font color="#0000BB">$_SERVER</font><font color="#007700">[</font><font color="#DD0000">'PHP_SELF'</font><font color="#007700">]);<br /></font><font color="#0000BB">$this&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">$parts</font><font color="#007700">[</font><font color="#0000BB">count</font><font color="#007700">(</font><font color="#0000BB">$parts</font><font color="#007700">)&nbsp;-&nbsp;</font><font color="#0000BB">1</font><font color="#007700">];<br /></font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$this</font><font color="#007700">,&nbsp;</font><font color="#0000BB">0</font><font color="#007700">,&nbsp;-</font><font color="#0000BB">4</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font></font></code></div></p>
<p>What this does is isolate the filename part of the path from the subdirectory(ies) it resides in.  The first command creates an array called parts from whatever is between the slashes ('/') of the path.  The next determines the filename &amp; extension based upon the index value of the last array element.  Finally, we pull off the extension in the third command.  The second and third commands could be combined, but there's a reason I keep them separate that I'll explain in a bit.</p>
<p>Okay, we have the name of the page at our disposal, what do we do with it?  In our navigation, we can now make decisions about what to do when a certain page is loaded.  Here's an example of one navigation element:</p>
<p><div class="codeblock"><code>&lt;div id=&quot;navigation&quot;&gt;<br />&lt;ul&gt;<br />&lt;li<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">if&nbsp;(</font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">==&nbsp;</font><font color="#DD0000">'guestbook'</font><font color="#007700">)&nbsp;echo&nbsp;</font><font color="#DD0000">"&nbsp;class=\"there\""</font><font color="#007700">;&nbsp;</font><font color="#0000BB">?&gt;</font></font>&gt;<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">if&nbsp;(</font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">!=&nbsp;</font><font color="#DD0000">'guestbook'</font><font color="#007700">)&nbsp;{&nbsp;</font><font color="#0000BB">?&gt;</font></font>&lt;a href=&quot;guestbook.php&quot;&gt;<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">}&nbsp;</font><font color="#0000BB">?&gt;</font></font>Guestbook<font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">if&nbsp;(</font><font color="#0000BB">$pname&nbsp;</font><font color="#007700">!=&nbsp;</font><font color="#DD0000">'guestbook'</font><font color="#007700">)&nbsp;echo&nbsp;</font><font color="#DD0000">"&lt;/a&gt;"</font><font color="#007700">;&nbsp;</font><font color="#0000BB">?&gt;</font></font>&lt;/li&gt;</code></div></p>
<p>Here's what's happening in this list item.  Before we close the LI tag, we check to see if the page name (<span style="font-style:italic">$pname</span>) matches the page this item links to.  If it does, we add the class named <span style="font-style:italic">there</span> which will invoke different styling for that item to indicate on the item itself we're on that page. What follows is a determination whether or not we need to make this item a link based upon whether the page is loaded or not.</p>
<p>Looks like a lot of typing, but if you have a means of saving blocks of code that you use frequently, you can save off one of these lines and copy it to your header or footer the number of times to match the number of navigation elements you have.  Now you'll have an automatically changing navigation system that'll reflect what page you're on without having to remember to code it on the page itself.  And since it's located in one easy-to-edit place, you can modify it as needed when changes happen to your site and it will be reflected in all the pages.</p>
<p>Another feature I usually add to the footer of pages is the last modified date.  With information we grabbed in the header and the following code, it will automatically be changed as we update a page.</p>
<p><code>page last modified <font color="#000000"><font color="#0000BB">&lt;?php&nbsp;</font><font color="#007700">echo&nbsp;</font><font color="#0000BB">date</font><font color="#007700">(</font><font color="#DD0000">"m/j/y&nbsp;h:i"</font><font color="#007700">,&nbsp;</font><font color="#0000BB">filemtime</font><font color="#007700">(</font><font color="#0000BB">$this</font><font color="#007700">));&nbsp;</font><font color="#0000BB">?&gt;</font></font></code></p>
<p>This prints the modified date of the filename (<span style="font-style:italic">$this</span>), giving the date and time that is stored for that page.  Nothing earth-shattering, but a handy thing that some visitors look at to determine how old the information is on a particular page.</p>
<p>Next time, we'll explore some more ways to employ PHP to make your static <span style="font-style:italic">CMS</span> a little less static seeming.  Till then, happy coding! :^{&gt;</p>
    ]]></content>
  </entry>
  <entry>
    <title>Photoshop Motion Zoom</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/tutorial/photoshop_motion_zoom" />
    <id>http://www.code2design.com/tutorial/photoshop_motion_zoom</id>
    <published>2007-04-01T00:20:28-04:00</published>
    <updated>2007-04-17T23:19:35-04:00</updated>
    <author>
      <name>WarpNacelle</name>
    </author>
    <category term="Motion Zoom" />
    <summary type="html"><![CDATA[<p>I've been absent from this site for a while, so I thought I'd jump back in with a simple yet effective Photoshop tutorial.<br />
This tutorial assumes you know how to create a basic selection and understand layers - but that's really it.  I will be using Photoshop CS2 on Windows XP.<br />
I call this effect, for lack of a better term, a "motion zoom".  This effect adds a blur that creates a zoom focused on a selected item in a picture.<br />
I have attached the photo I will be using called "skateboard.jpg".  I find that the best pictures for this effect are ones with a busy background.  Solid colors or plain backgrounds limit the effect.<br />
So, open up "skateboard.jpg" into Photoshop.<br />
-- Double click on the layer called "Background" to make it available to edit. I renamed it to "Zoom Background".  You may do so if you wish.<br />
-- Next, select your "lasso" tool (L) and select around the skateboarder like so:</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>I've been absent from this site for a while, so I thought I'd jump back in with a simple yet effective Photoshop tutorial.</p>
<p>This tutorial assumes you know how to create a basic selection and understand layers - but that's really it.  I will be using Photoshop CS2 on Windows XP.</p>
<p>I call this effect, for lack of a better term, a "motion zoom".  This effect adds a blur that creates a zoom focused on a selected item in a picture.</p>
<p>I have attached the photo I will be using called "skateboard.jpg".  I find that the best pictures for this effect are ones with a busy background.  Solid colors or plain backgrounds limit the effect.</p>
<p>So, open up "skateboard.jpg" into Photoshop.</p>
<p>-- Double click on the layer called "Background" to make it available to edit. I renamed it to "Zoom Background".  You may do so if you wish.</p>
<p>-- Next, select your "lasso" tool (L) and select around the skateboarder like so:</p>
<p><img src="http://www.morriswebsite.com/ss/sshot1.jpg" alt="" class="bb-image" /></p>
<p>-- Now we will prepare the image for the effect.</p>
<p>-- We need to stick Mr. Selection onto its own layer.  So go to your menu bar and select: LAYER -&gt; NEW -&gt; LAYER VIA COPY (or use the keyboard shortcut: CTRL + J)</p>
<p>You will now have two layers.  Your selection by itself and the original image:</p>
<p><img src="http://www.morriswebsite.com/ss/sshot2.jpg" alt="" class="bb-image" /></p>
<p>-- Now we apply the cool effect.  Click on the bottom layer ("Zoom Background") to select it, go up to your menu bar and select: FILTER -&gt; BLUR -&gt; RADIAL BLUR.</p>
<p>-- Make your blur settings identical to the image below:</p>
<p><img src="http://www.morriswebsite.com/ss/sshot3.jpg" alt="" class="bb-image" /></p>
<ul>
</li><li>Amount: 70
</li><li>Blur Method: Zoom
</li><li>Quality: Good
</ul>
<p>* Note: You can click in the "Blur Center" window and move the center of the zoom around.  This can be used if you decide to use a picture where your selected part is in a corner or something like that.</p>
<p>-- Click "OK" and you now see the skateboarder framed in a very cool looking zoom.</p>
<p>-- We are going to fine tune it a bit.  Select your blur tool - the icon that looks like a water drop - or hit the "R" key.  (If you don't see it, click and hold your mouse over the highlighted tool - after hitting R - and you will see it pop up as a sub-menu choice.</p>
<p>-- Select the top layer (Layer 1) and make sure your blur brush is a small size.  To adjust this on the fly hit your bracket keys: "[" or "]".</p>
<p>-- Blur the outside edge of the skateboarder and he will blend into the zoom layer very smoothly.</p>
<p>-- Your finished product should look something like this (I cropped mine a bit for effect):</p>
<p><img src="http://www.morriswebsite.com/ss/skateboard_final.jpg" alt="" class="bb-image" /></p>
<p>* If you want, select the bottom layer and play around with it to increase the effect.  You can de-saturate it so the skateboarder pops out in color, or mess with the colors to give it a psychedelic look.</p>
<p>And that's it.  A simple yet effective effect!</p>
    ]]></content>
  </entry>
  <entry>
    <title>Persecution</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/david/persecution" />
    <id>http://www.code2design.com/david/persecution</id>
    <published>2007-03-25T20:03:05-04:00</published>
    <updated>2007-03-25T20:03:05-04:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="David" />
    <category term="Persecution" />
    <category term="Satan" />
    <summary type="html"><![CDATA[<p>As I was reading the first chapter of 2 Thessalonians, I started thinking about a few things; particularly - persecution.  Having been born and raised in America, I've never really known "persecution".  Because I am a Christian, I may have been made fun of, rejected, or disliked - but I wouldn't consider those as "persecution"; more like inconveniences.  However, this chapter explains persecution in one of the ways it should be seen, so I’d like to share with you. ;)<br />
Quote:Dear brothers and sisters, we always thank God for you, as is right, for we are thankful that your faith is flourishing and that you are all growing in love for each other.  - 2 Thessalonians 1:3</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>As I was reading the first chapter of 2 Thessalonians, I started thinking about a few things; particularly - persecution.  Having been born and raised in America, I've never really known "persecution".  Because I am a Christian, I may have been made fun of, rejected, or disliked - but I wouldn't consider those as "persecution"; more like inconveniences.  However, this chapter explains persecution in one of the ways it should be seen, so I’d like to share with you. ;)</p>
<p><div class="bb-quote">Quote:<blockquote class="bb-quote-body">Dear brothers and sisters, we always thank God for you, as is right, for we are thankful that your faith is flourishing and that you are all growing in love for each other.  - 2 Thessalonians 1:3</blockquote></div></p>
<p>Two key elements right there! A strong faith, and love for others.  I don't think you can have two more powerful weapons than faith and love.  I know you certainly can't stand against Satan without them!  They are the very core of a Christian. "There are three things that will endure (Forever) - faith, hope, and love - and the greatest of these is love." - 1 Corinthians 13:13</p>
<p><div class="bb-quote">Quote:<blockquote class="bb-quote-body">We proudly tell God's other churches about your endurance and faithfulness in all the persecutions and hardships you are suffering.  But God will use this persecution to show his justice.  For He will make you worthy of his kingdom, for which you are suffering, and in His justice He will punish those who persecute you. - 2 Thessalonians 1:4-6</blockquote></div></p>
<p><div class="bb-quote">Quote:<blockquote class="bb-quote-body">And so we keep on praying for you, that our God will make you worthy of the life to which he called you.  And we pray that God, by his power, will fulfill all your good intentions and faithful deeds.  Then everyone will give honor to the name of our Lord Jesus because of you, and you will be honored along with him.  This is made possible because of the undeserved favor of our God and Lord, Jesus Christ. - 2 Thessalonians 1:11-12</blockquote></div></p>
<p>Interesting...  did you catch it? "For He will make you worthy of his kingdom"</p>
<p>Let me tell you something - armies don't attack something unless it's a threat. Period. The same thing goes for Satan and his fallen angels - they wont attack you unless you’re a threat. If you are going through life, minding your own business and staying away from God, you have nothing to worry about! You pose no threat to Satan and you're walking right down the path he wants you to go - the path to hell. So, why would he bother you?</p>
<p>However, if you're interrupting Satan's plans, if you're doing God's will and sharing God's love with others - you just made yourself a target.  You're now fighting on God's side - against Satan. So, you can be sure that Satan will send any kind of persecution he can to hold you back, cause you pain, and get you to stumble.  He doesn't want you to keep doing what you're doing - you'll ruin his plans!</p>
<p>As you draw closer to God and start following his will for your life more and more, you'll encounter stronger persecution.  The bigger a threat you are; the more Satan will work to stop you.  Just look at the lives of the Apostles, Paul, Martin Luther, and Jesus.  They had lots of trouble from Satan's attacks and traps.  They were HUGE threats.  But you know what? Their lives and their suffering was a testament to their worthiness of the kingdom of God.</p>
<p>They showed their faith in Christ and their love for others through their sacrifices.  And with each new challenge they looked to God, and He gave them the strength and the wisdom to continue doing His will. He made them worthy of His kingdom. "And we pray that God, by his power, will fulfill all your good intentions and faithful deeds.  Then everyone will give honor to the name of our Lord Jesus because of you, and you will be honored along with him."</p>
<p>If you are in the game of life - whether on God's side or Satan's side - you're going to get tackled.  Someone will see you as a threat and try to take you down.  You're playing for the goal - our goal is Christ and a non-stop worship concert in heaven where God reigns.  So if you suffer persecution you know that you're making a difference.  A difference Satan wants to stop.</p>
<p><div class="bb-quote">Quote:<blockquote class="bb-quote-body">And God will provide rest for you who are being persecuted and also for us when the Lord Jesus appears from heaven.  He will come with his mighty Angels, in flaming fire, bringing judgment on those who don't know God and on those who refused to obey the good news of our Lord Jesus.  They will be punished with everlasting destruction, forever separated from the Lord and from his glorious power when he comes to receive glory and praise from his holy people.  And you will be among those praising Him on that day, for you believe what we testified about Him. - 2 Thessalonians 1:7-10</blockquote></div></p>
<p>Like I said, I can remember the last time I was persecuted.  So this really has me thinking about whether or not I'm living my life for God - or for myself. Am I a threat to Satan or not? Because one day everything I do for myself will be burned up - It just plain won't matter. (Not to mention the fact that the life God has for me is 1000000x better.)</p>
<p>So let me ask you this - if you haven't been tackled, if you haven't faced persecution, if you are just sitting on the sidelines never going anywhere - seriously, what is the point of your life?</p>
    ]]></content>
  </entry>
  <entry>
    <title>C2D&#039;s Open Search and Razor Blades</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/david/c2ds_open_search_and_razor_blades" />
    <id>http://www.code2design.com/david/c2ds_open_search_and_razor_blades</id>
    <published>2007-02-28T13:04:06-05:00</published>
    <updated>2007-02-28T13:06:03-05:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="David" />
    <category term="Flash" />
    <category term="Site News" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter-->
<p>Time for more (than less) information on the recent updates to Code2Design.</p>
<p>Yes, C2D is now <a href="http://opensearch.a9.com/" target="_blank">open search</a> compatible. Now you can search all of Code2Design.com right from your browser!</p>
<p>To install the browser plug-in for Firefox, Opera, or Internet Explorer 7 simply visit any page on C2D and click the highlighted search box to add us to your list of favorite search engines!</p>
<p><img src="/images/c2d_os.jpg"></p>
<p>However, if you are anything like me, you probably never even use that feature. ;) So, now is a great chance to improve your skills, find useful information, and help test-out our new search plug-in. Boy are you efficient! </p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Time for more (than less) information on the recent updates to Code2Design.</p>
<p>Yes, C2D is now <a href="http://opensearch.a9.com/" target="_blank">open search</a> compatible. Now you can search all of Code2Design.com right from your browser!</p>
<p>To install the browser plug-in for Firefox, Opera, or Internet Explorer 7 simply visit any page on C2D and click the highlighted search box to add us to your list of favorite search engines!</p>
<p><img src="/images/c2d_os.jpg"></p>
<p>However, if you are anything like me, you probably never even use that feature. ;) So, now is a great chance to improve your skills, find useful information, and help test-out our new search plug-in. Boy are you efficient! </p>
<p>In other news, the <a href="http://www.code2design.com/new_projects" class="bb-url">Bookmark System</a> I posted about earlier looks like it has become a simple CMS project! Yes, I have always wanted a CMS that was secure, simple to hack, and didn’t need updates. (Like a baby version of <a href="http://drupal.org" class="bb-url">Drupal</a>.) So out of this desire, I will be using the same system I am building for my bookmarks as the spring board for a CMS system (and tutorials) that will be easy to use/hack without the need for 4+ years of PHP experience to follow the code. Yes, I see that smile on your face…  ;)</p>
<p>Recently, we have been receiving about 100 unique visitors each day and now that I have posted 8 tutorials and lessons to <a href="http://pixel2life.com" class="bb-url">Pixel2Life</a> - we should get hit hard by some new waves of visitors when the time comes. I love waves.  :]</p>
<p>I have not uploaded any new videos lately because I have been waiting for my <a href="http://shop3.outpost.com/product/5119906" class="bb-url">new Hard Drive</a> to arrive. Once I get it I need to start on the AutoCAD lessons ASAP! Then I will go back to PHP lessons (I am on #9) - unless someone else wants something else… (Hint, Hint)</p>
<p>Also, I would <span style="font-style:italic">really</span> appreciate it if you could take the time to bookmark us with some of the icons below. Bookmaking helps spread the word about C2D. (The more visitors - the more members, the more members – the more tutorials! Yay! )</p>
<p>Oh, and for those of you who are having a bad day - I have just the thing:<br />
<a href="http://flash.code2design.com/movies/RazorBLades.swf" class="bb-url">The Razor Blade Movie</a></p>
    ]]></content>
  </entry>
  <entry>
    <title>Rooted in Christ</title>
    <link rel="alternate" type="text/html" href="http://www.code2design.com/david/rooted_in_christ" />
    <id>http://www.code2design.com/david/rooted_in_christ</id>
    <published>2007-02-25T14:02:58-05:00</published>
    <updated>2007-02-25T14:02:58-05:00</updated>
    <author>
      <name>David</name>
    </author>
    <category term="David" />
    <category term="Growth" />
    <category term="Living for Christ" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><!--paging_filter-->
<p>"My goal is that they will be encouraged and knit together by strong ties of love.  I want them to have full confidence because they have complete understanding of God's secret plan, which is Christ himself.  In him lie hidden all the treasures of wisdom and knowledge.  I'm telling you this so that no one will be able to deceive you with persuasive arguments." - Colossians 2:2-4</p>
<p>I read a great article on <a href="http://www.navpress.com/EPubs/PrinterFriendly/1/1.97.9.html" class="bb-url">The 10 Questions To Ask To Make Sure You're Still Growing</a>.  And I realized I was lacking in some areas, actually - I was lacking in all areas.  Looking back over the past few months, I see that I'm still the same person I was then.  I still do the same things, and I still know the same things...  But that's not God's plan for us!  He wants to bring us closer to Him, he wants us to grow in our knowledge and love for Him.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>"My goal is that they will be encouraged and knit together by strong ties of love.  I want them to have full confidence because they have complete understanding of God's secret plan, which is Christ himself.  In him lie hidden all the treasures of wisdom and knowledge.  I'm telling you this so that no one will be able to deceive you with persuasive arguments." - Colossians 2:2-4</p>
<p>I read a great article on <a href="http://www.navpress.com/EPubs/PrinterFriendly/1/1.97.9.html" class="bb-url">The 10 Questions To Ask To Make Sure You're Still Growing</a>.  And I realized I was lacking in some areas, actually - I was lacking in all areas.  Looking back over the past few months, I see that I'm still the same person I was then.  I still do the same things, and I still know the same things...  But that's not God's plan for us!  He wants to bring us closer to Him, he wants us to grow in our knowledge and love for Him.</p>
<p>No one makes a friend with someone they like, gets to know them a little, and then decides that's as far as they need to go in that friendship. People don't think, "I know enough about them, and they know enough about me so we don't need to do any more together or get to know each other anymore, we will just stay friends like this forever." No, of course not! If you meet someone that you enjoy spending time with, you want to get to know them better and you want to do more and more with them.  Making friends isn't about having someone <span style="font-style:italic">to call a friend</span>, it's about <span style="font-style:italic">having a friend</span>.  It's about finding people that will become a part of your life and that will help you.</p>
<p>That is what your relationship with Christ is. (Only better!)  When you accept Jesus as your Lord and Savior, you are inviting Him into your life.  You are saying, "I believe what you did for me on the cross, and I want you to be the Lord of my life".  (and I want to know you better.)</p>
<p><quote>And now, just as you accepted Christ Jesus as your Lord, you must continue to live in obedience to him.  Let your roots grow down deep into him and draw up nourishment from him, so you will grow in faith, strong and vigorous in the truth you were taught.  Let your lives overflow with Thanksgiving for all he has done. - Colossians 2:6-7</quote></p>
<p>We need that nourishment from Him to grow - we need to take our walk with Christ to the next level.  It's time to stop being a sick little tree, and start drawing from God's wisdom and power to transform us into a mighty oak.  Trees with shallow roots are easily killed and blown over by the wind, but a tree with a deep taproot can withstand the wind and pull from the ground the water to survive the scorching heat.</p>
<p>So after thinking about this, I realized the way we can grow to know Him more - communication.  Just like with a friend, or loved one, you have to communicate with them to get anywhere.  (I don't know about you, but just staring at someone has never really helped me.)  God is the same way, you need to talk to Him and hear what he has say. We need to pray and read God's word; the Bible.  Through God's word, He speaks to us, so if we never read God's word - how are we supposed to know what he says? And by the same token, we need to talk to Him through prayer. It is not that God doesn't know what you need or what you're thinking - it's just that He is waiting for you to ask Him for it.  God wants to bless you, but he won't force something on you without you're asking.</p>
<p>You know, I spend a lot of time on the computer - a LOT - and yet I don't have much to show for most of it.  The same thing with TV or movies, what has it really gained me? Is the world a better place now? Do I understand God better? Have I made more friends? Do I have a better portfolio?  - No, the only thing I got out of it was temporary enjoyment.  Now don't get me wrong, I'm not going to stop watching movies and going on the computer, but as I looked at how I spent my time it occurred to me what I could do better.  How much of my day is spent growing my walk with my Creator? 15 minutes, 5 minutes, or even 5 seconds? Really, how am I going to grow without ever planting any roots?</p>
<p>So, I'm sick of being pushed around by the wind; it's time to start growing.  Starting today, I'm going to make it my goal to spend time reading God's word <span style="font-style:italic">before</span> I go on the computer. I'm going to spend that 15 minutes, 1/96th of my day, saying, "God what do you want to show me today?".  And I don't care what excuse Satan comes up with as to why something else is more important, or why I can skip reading the Bible today, I'm going to stick with it.  Because nothing is more important than my relationship, my <span style="font-style:italic">eternal</span> relationship, with God. (No, not even that job-offer email you have been waiting for from Bill Gates)</p>
<p><quote>Four in Christ the fullness of God lives in a human body, and you are complete through your union with Christ. He is the lord over every ruler and authority in the universe. - Colossians 2:9-10</quote></p>
<p>By the way, if you are looking for more ways to spend time with God, I recommend listening to the <a href="http://www.thruthebible.org/" class="bb-url">Thru the Bible</a> Mp3's while in the gym, having prayer time on that long drive to work, and finding a weekday Bible Study. Plus, wherever else you could fit something in. Remember, if something is important to you - you'll find the time... ;)</p>
<p><quote>So don't let anyone condemn you for what you eat or drink, or for not celebrating certain holidays or new moon ceremonies or Sabbath's.  For these rules were only shadows of the real thing, Christ himself.  Don't let anyone condemn you by insisting on self-denial.  And don't let anyone say you must worship angels, even though they say they've had visions about this.  These people claimed to be so humble but their sinful minds have made them proud.  But they are not connected to Christ, the head of the body.  For we are joined together in his body by strong sinews, and we grow only as we get our nourishment and strength from God. - Colossians 2:16-19</quote></p>
<p><quote>See to it that no one takes you captive through philosophy and empty deception, according to the tradition of men, according to the elementary principals of the world, rather than according to Christ. - Colossians 2:8</quote></p>
    ]]></content>
  </entry>
</feed>
<!-- Rendered in 1.0442 -->