<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Coding Mix</title><link>http://www.codingmix.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodingMix" /><description></description><language>en</language><managingEditor>noreply@blogger.com (Csabi)</managingEditor><lastBuildDate>Thu, 23 Feb 2012 19:15:09 PST</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">41</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">25</openSearch:itemsPerPage><feedburner:info uri="codingmix" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>CodingMix</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://www.podnova.com/add.srf?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.podnova.com/img_chicklet_podnova.gif">Subscribe with Podnova</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://odeo.com/listen/subscribe?feed=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://odeo.com/img/badge-channel-black.gif">Subscribe with ODEO</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FCodingMix" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item><title>Upload an image and downsize it (in KB`s) using php and GD</title><link>http://feedproxy.google.com/~r/CodingMix/~3/NCdwKFvUDPA/php-gd-upload-image-downsize-compress.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sat, 15 Jan 2011 03:41:15 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8181027301628160392</guid><description>If you have a website where you let your users to upload images, you know that even the small images (around 100x100) can reach 50 - 100KB. This is way too much, when you could simply downsize the image to around 1 - 5KB, this is only the 1 - 5% of the size of the original image. Just imagine the benefits of downsizing 100.000 images...&lt;br /&gt;Bellow is an image before and after resizing: &lt;div id="full-post"&gt;&lt;div class="code" style="width:250px;text-align:center;float:left;"&gt;&lt;b&gt;Before&lt;/b&gt;&lt;br /&gt;&lt;img src="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TTGCPr-nXDI/AAAAAAAAARE/4JiKiIIHmzs/s1600/example.jpg" border="0" alt="before resizing"/&gt;&lt;br /&gt;24.80KB&lt;/div&gt;&lt;div class="code" style="width:250px;text-align:center;float:left;"&gt;&lt;b&gt;After&lt;/b&gt;&lt;br /&gt;&lt;img src="http://2.bp.blogspot.com/_Ok7mVUxPcsk/TTGDXe5VtjI/AAAAAAAAARM/8131J6AA2xw/s1600/example.jpg" border="0" alt="after resizing" /&gt;&lt;br /&gt;3.52KB&lt;/div&gt;So let`s begin downsizing those images...&lt;br /&gt;&lt;b&gt;The upload form&lt;/b&gt;&lt;br /&gt;&lt;i&gt;upload-form.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;form action=&amp;quot;upload.php&amp;quot; method=&amp;quot;POST&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;MAX_FILE_SIZE&amp;quot; value=&amp;quot;100000&amp;quot; /&amp;gt;&lt;br /&gt;Select image: &amp;lt;input name=&amp;quot;theimage&amp;quot; type=&amp;quot;file&amp;quot; /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Upload image&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/div&gt;&lt;b&gt;enctype=&amp;quot;multipart/form-data&amp;quot;&lt;/b&gt; - this line tells the server that you want to send a file&lt;br /&gt;&lt;b&gt;MAX_FILE_SIZE&lt;/b&gt; - limits the maximum file size in bytes&lt;br /&gt;&lt;b&gt;type=&amp;quot;file&amp;quot;&lt;/b&gt; - this is the file selecting input&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Checking the image&lt;/b&gt;&lt;br /&gt;First we need to check the file for 3 different problems: &lt;br /&gt;- it was submitted or not ?&lt;br /&gt;- it was uploaded ?&lt;br /&gt;- it is too big ?&lt;br /&gt;&lt;i&gt;upload.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;b&gt;Check image type&lt;/b&gt;&lt;br /&gt;Now we will check the type of the file, because we will accept only .jpg .gif and .png. At this step we will use some GD, too, because we will put our image in a variable:&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;      switch($_FILES['theimage']['type']){&lt;br /&gt;         case 'image/gif':&lt;br /&gt;         $image = imagecreatefromgif($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/jpeg':&lt;br /&gt;         case 'image/pjpeg':&lt;br /&gt;         $image = imagecreatefromjpeg($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/png':&lt;br /&gt;         $image = imagecreatefrompng($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      if(!isset($image)){&lt;br /&gt;         echo 'Only .gif, .jpg or .png images are allowed!';&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;b&gt;Working with transparent images&lt;/b&gt;&lt;br /&gt;We will downsize the images by converting it to .jpg. The jpg images can not be transparent and when the user uploads a transparent image, the transparent part will be painted in black. To make the transparent part white we need to create a white image with the same size as our uploaded image and then copy the uploaded image over the white image:&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;      switch($_FILES['theimage']['type']){&lt;br /&gt;         case 'image/gif':&lt;br /&gt;         $image = imagecreatefromgif($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/jpeg':&lt;br /&gt;         case 'image/pjpeg':&lt;br /&gt;         $image = imagecreatefromjpeg($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/png':&lt;br /&gt;         $image = imagecreatefrompng($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      if(!isset($image)){&lt;br /&gt;         echo 'Only .gif, .jpg or .png images are allowed!';&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;         $size = getimagesize($_FILES['theimage']['tmp_name']);&lt;br /&gt;         $background = imagecreatetruecolor($size[0],$size[1]);&lt;br /&gt;         $white = imagecolorallocate($background,255,255,255);&lt;br /&gt;         imagefill($background,0,0,$white);&lt;br /&gt;         imagecopy($background,$image,0,0,0,0,$size[0],$size[1]);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;b&gt;Downsize the image&lt;/b&gt;&lt;br /&gt;This is the final step, when we save the image in .jpg format: &lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;      switch($_FILES['theimage']['type']){&lt;br /&gt;         case 'image/gif':&lt;br /&gt;         $image = imagecreatefromgif($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/jpeg':&lt;br /&gt;         case 'image/pjpeg':&lt;br /&gt;         $image = imagecreatefromjpeg($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/png':&lt;br /&gt;         $image = imagecreatefrompng($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      if(!isset($image)){&lt;br /&gt;         echo 'Only .gif, .jpg or .png images are allowed!';&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;         $size = getimagesize($_FILES['theimage']['tmp_name']);&lt;br /&gt;         $background = imagecreatetruecolor($size[0],$size[1]);&lt;br /&gt;         $white = imagecolorallocate($background,255,255,255);&lt;br /&gt;         imagefill($background,0,0,$white);&lt;br /&gt;         imagecopy($background,$image,0,0,0,0,$size[0],$size[1]);&lt;br /&gt;         $image = $background;&lt;br /&gt;         $filename = explode(&amp;quot;.&amp;quot;,$_FILES['theimage']['name']);&lt;br /&gt;         $filename = $filename[0];&lt;br /&gt;         imagejpeg($image,$_SERVER['DOCUMENT_ROOT'] . '/thumbnails/' . $filename . '.jpg',90);&lt;br /&gt;         imagedestroy($image);&lt;br /&gt;         echo 'Your image: &amp;lt;img src=&amp;quot;/thumbnails/' . $filename . '.jpg&amp;quot; /&amp;gt;';&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;If you have any questions please don`t hesitate to ASK!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8181027301628160392?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2qXekbBbKofQJH3pIcOmzGePIjI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2qXekbBbKofQJH3pIcOmzGePIjI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2qXekbBbKofQJH3pIcOmzGePIjI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2qXekbBbKofQJH3pIcOmzGePIjI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/NCdwKFvUDPA" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-15T03:41:15.851-08:00</app:edited><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TTGCPr-nXDI/AAAAAAAAARE/4JiKiIIHmzs/s72-c/example.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">9</thr:total><feedburner:origLink>http://www.codingmix.com/2011/01/php-gd-upload-image-downsize-compress.html</feedburner:origLink></item><item><title>Private chat room script</title><link>http://feedproxy.google.com/~r/CodingMix/~3/4lWkAdU22qg/private-chat-room-script.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 04 Jan 2012 00:47:49 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5652676838774154670</guid><description>Finally my private chat room is ready! I`we used jQuery, PHP and 2 MySQL tables to write this script. This is the first version, this is some kind of beta version, because I hadn`t test it yet, because it needs at least 2 users to work... Here is a live demo, have fun with it and please tell me about the errors: &lt;div id="full-post"&gt;&lt;iframe src="" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;NOTES: &lt;br /&gt;Everything is refreshed each 15 seconds. &lt;br /&gt;An user is logged out after 10 minutes of inactivity.&lt;br /&gt;Each message is kept for 30 minutes.&lt;br /&gt;An users name is highlighted with orange if the user sent you a message.&lt;br /&gt;The selected username is highlighted with red.&lt;br /&gt;&lt;br /&gt;As I said, we will need two mysql tables: one to hold the users (username, ip, last activity date) and one for the messages (from, to, message, date). Here is my code to create the tables: &lt;br /&gt;&lt;i&gt;table1.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect(&amp;quot;host&amp;quot;, &amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_select_db(&amp;quot;database&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_query(&amp;quot;CREATE TABLE chatusers(&lt;br /&gt;   username VARCHAR(30),&lt;br /&gt;   ip CHAR(15),&lt;br /&gt;   lastactive INT UNSIGNED,&lt;br /&gt;   PRIMARY KEY(username)&lt;br /&gt;)&amp;quot;)&lt;br /&gt;or die(mysql_error()); &lt;br /&gt;echo &amp;quot;Table Created!&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;table2.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect(&amp;quot;host&amp;quot;, &amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_select_db(&amp;quot;database&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_query(&amp;quot;CREATE TABLE messages(&lt;br /&gt;   messagefrom VARCHAR(30),&lt;br /&gt;   sendto VARCHAR(30),&lt;br /&gt;   message VARCHAR(255),&lt;br /&gt;   date INT UNSIGNED&lt;br /&gt;)&amp;quot;)&lt;br /&gt;or die(mysql_error()); &lt;br /&gt;echo &amp;quot;Table Created!&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;It`s hard to explain how it works... but I will try to. At the start if your ip is not in the database you will be asked for an username and you will be added to the database and a list with the online users is generated by the &lt;i&gt;onlineusers.php&lt;/i&gt; file. When you click on somebody the messages sent by that person to you and the messages sent by you to that person are shown by the &lt;i&gt;show-messages.php&lt;/i&gt; file. When you write a message and press the send button then your message will be sent to the selected user by saving it on the messages table.&lt;br /&gt;&lt;br /&gt;Here is the rest of the code:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;#chat {&lt;br /&gt;   width:500px;&lt;br /&gt;   margin:0 auto;&lt;br /&gt;}&lt;br /&gt;#login {&lt;br /&gt;   width:230px;&lt;br /&gt;   height:50px;&lt;br /&gt;   margin:100px;&lt;br /&gt;   border:1px solid black;&lt;br /&gt;   text-indent:10px;&lt;br /&gt;}&lt;br /&gt;.onlineuser {&lt;br /&gt;   padding:0 10px;&lt;br /&gt;   background:#CCC;&lt;br /&gt;   margin-left:2px;&lt;br /&gt;}&lt;br /&gt;.yes {&lt;br /&gt;   background:#F90;&lt;br /&gt;}&lt;br /&gt;.message {&lt;br /&gt;   float:left;&lt;br /&gt;   border:1px solid black;&lt;br /&gt;   width:498px;&lt;br /&gt;}&lt;br /&gt;.messdate {&lt;br /&gt;   float:right;&lt;br /&gt;}&lt;br /&gt;.selected {&lt;br /&gt;   background:red;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;script src=&amp;quot;http://code.jquery.com/jquery-latest.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot;&amp;gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?php mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;)) == 0){ ?&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;login&amp;quot;&amp;gt;&lt;br /&gt;Select username: &amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;usernameinput&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Login&amp;quot; id=&amp;quot;loginbutton&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?php } &lt;br /&gt;else {&lt;br /&gt;mysql_query(&amp;quot;UPDATE chatusers SET lastactive = &amp;quot; . time() . &amp;quot; WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;);&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;onlineusers&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;send&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; id=&amp;quot;sendbutton&amp;quot; disabled=&amp;quot;disabled&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?php } ?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;$('#loginbutton').click(function (){&lt;br /&gt;   if($(this).attr(&amp;quot;disabled&amp;quot;) != &amp;quot;disabled&amp;quot;){&lt;br /&gt;      var error = $.ajax({ &lt;br /&gt;         url: &amp;quot;login.php&amp;quot;,&lt;br /&gt;         data: &amp;quot;username=&amp;quot; + $('#usernameinput').val(),&lt;br /&gt;         async:false&lt;br /&gt;      }).responseText;&lt;br /&gt;      if(error != ''){&lt;br /&gt;         alert(error);&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;         location.reload();&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;var from = '';&lt;br /&gt;showusers();&lt;br /&gt;function showusers(){&lt;br /&gt;   $('#onlineusers').html($.ajax({&lt;br /&gt;      url: 'onlineusers.php?x=' + Math.random() + '&amp;amp;selected=' + from, &lt;br /&gt;      async:false&lt;br /&gt;   }).responseText);&lt;br /&gt;   $('#messages').html($.ajax({&lt;br /&gt;      url: 'show-messages.php',&lt;br /&gt;      data: '?x=' + Math.random() + '&amp;amp;from=' + from,&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText);&lt;br /&gt;   setTimeout('showusers()',15000); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$('.onlineuser').click(function (){&lt;br /&gt;   from = $(this).html();&lt;br /&gt;   $('#messages').html($.ajax({&lt;br /&gt;      url: 'show-messages.php',&lt;br /&gt;      data: '?x=' + Math.random() + '&amp;amp;from=' + $(this).html(),&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText); &lt;br /&gt;   $('#sendbutton').removeAttr(&amp;quot;disabled&amp;quot;);&lt;br /&gt;   showusers();&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;$('#sendbutton').click(function (){&lt;br /&gt;   if($(this).attr(&amp;quot;disabled&amp;quot;) != &amp;quot;disabled&amp;quot;){&lt;br /&gt;      var message = $('#message').val();&lt;br /&gt;      $.ajax({&lt;br /&gt;         url: 'send.php?to=' + from + '&amp;amp;mes=' + message&lt;br /&gt;      });&lt;br /&gt;      $('#message').val('');&lt;br /&gt;      showusers();&lt;br /&gt;   }&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;i&gt;onlineusers.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;mysql_query(&amp;quot;UPDATE chatusers SET lastactive = &amp;quot; . time() . &amp;quot; WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;);&lt;br /&gt;$users = mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip != '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;); &lt;br /&gt;mysql_query(&amp;quot;DELETE FROM chatusers WHERE lastactive &amp;lt; &amp;quot; . (time() - 600)) or die(mysql_error());&lt;br /&gt;echo 'Online users: ';&lt;br /&gt;$username = mysql_fetch_array(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;));&lt;br /&gt;$username = $username['username'];&lt;br /&gt;while($row = mysql_fetch_array($users)){&lt;br /&gt;   $class = '';&lt;br /&gt;   $class2 = '';&lt;br /&gt;   if(mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM messages WHERE sendto = '&amp;quot; . $username . &amp;quot;' and messagefrom = '&amp;quot; . $row['username'] . &amp;quot;'&amp;quot;)) &amp;gt; 0) {&lt;br /&gt;      $class = 'yes';&lt;br /&gt;   }&lt;br /&gt;   if($_GET['selected'] == $row['username']){&lt;br /&gt;      $class2 = 'selected';&lt;br /&gt;   }&lt;br /&gt;   echo '&amp;lt;span class=&amp;quot;onlineuser ' . $class . ' ' . $class2 . '&amp;quot;&amp;gt;' . $row['username'] . '&amp;lt;/span&amp;gt;';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;$username = mysql_fetch_array(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;));&lt;br /&gt;$username = $username['username'];&lt;br /&gt;mysql_query(&amp;quot;DELETE FROM messages WHERE date &amp;lt; &amp;quot; . (time() - 1800));&lt;br /&gt;$result = mysql_query(&amp;quot;(SELECT * FROM messages WHERE messagefrom = '&amp;quot; . $_GET['from'] . &amp;quot;' and sendto = '&amp;quot; . $username . &amp;quot;' ORDER BY date ASC LIMIT 0, 10) UNION (SELECT * FROM messages WHERE messagefrom = '&amp;quot; . $username . &amp;quot;' and sendto = '&amp;quot; . $_GET['from'] . &amp;quot;' ORDER BY date ASC LIMIT 0, 10)&amp;quot;) or die(mysql_error()); &lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   if($row['messagefrom'] == $username){&lt;br /&gt;      $by = 'You';&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      $by = $_GET['from'];&lt;br /&gt;   }&lt;br /&gt;   echo '&amp;lt;div class=&amp;quot;message&amp;quot;&amp;gt;&amp;lt;b&amp;gt;' . $by . ':&amp;lt;/b&amp;gt; ' . $row['message'] . '&amp;lt;span class=&amp;quot;messdate&amp;quot;&amp;gt;' . date('g:i A M, d Y',$row['date']) . '&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;login.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM chatusers WHERE username = '&amp;quot; . $_GET['username'] . &amp;quot;'&amp;quot;)) == 0){&lt;br /&gt;   mysql_query(&amp;quot;INSERT INTO chatusers VALUES('&amp;quot; . $_GET['username'] . &amp;quot;', '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;', &amp;quot; . time() . &amp;quot;)&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   echo 'Username is taken';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;$username = mysql_fetch_array(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;));&lt;br /&gt;$username = $username['username'];&lt;br /&gt;mysql_query(&amp;quot;INSERT INTO messages VALUES('&amp;quot; . $username . &amp;quot;','&amp;quot; . $_GET['to'] . &amp;quot;', '&amp;quot; . $_GET['mes'] . &amp;quot;', &amp;quot; . time() . &amp;quot;)&amp;quot;) or die(mysql_error());&lt;br /&gt;?&amp;gt;&lt;/div&gt;If something is not working please let me know!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5652676838774154670?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6ct2V88QZ-WMXpYgnBRKNJDOCxI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6ct2V88QZ-WMXpYgnBRKNJDOCxI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6ct2V88QZ-WMXpYgnBRKNJDOCxI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6ct2V88QZ-WMXpYgnBRKNJDOCxI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/4lWkAdU22qg" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-04T00:47:49.405-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">23</thr:total><feedburner:origLink>http://www.codingmix.com/2010/12/private-chat-room-script.html</feedburner:origLink></item><item><title>Create SEO friendly URL`s using mod rewrite in PHP (.htaccess)</title><link>http://feedproxy.google.com/~r/CodingMix/~3/THJxx8t1S9k/mod-rewrite-seo-url-php-htaccess.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 19 Dec 2010 07:12:33 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4458784298246858128</guid><description>In this tutorial I will show you how to transform this: &lt;div class="code"&gt;http://www.mywebsite.com/tutorials.php?id=123&amp;title=mod_rewrite&amp;category=php&lt;/div&gt; into this &lt;div class="code"&gt;http://www.mywebsite.com/tutorials/php/mod_rewrite-123&lt;/div&gt;&lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;Why to rewrite your URL`s ?&lt;/b&gt;&lt;br /&gt;The main reason is because static URL`s (the second URL is static) are indexed more faster than dynamic URL`s (like the first one), because from a static URL is easier to understand what the page is about both for search engines and your visitors. When using dynamic URL`s there is an another problem: search engines are reading only the beginning of the long URL`s, so if your addresses are different only at the end, than search engines will see the same URL for all of your pages and from this reason none will be indexed.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How this works ?&lt;/b&gt;&lt;br /&gt;We will use Apache mod_rewrite. The mod_rewrite transforms back the second URL into the first URL, so the server will access the "ugly" address, but the visitors and the search engines will see the "clear" one. mod_rewrite simply rewrites the URL`s what meets specific conditions into addresses what are understood by the server.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Let`s rewrite it!&lt;/b&gt;&lt;br /&gt;The code what rewrites the website address needs to be placed in your &lt;b&gt;.htaccess&lt;/b&gt; file (if you don`t have it in your root folder, create it), the code is very short:&lt;div class="code"&gt;RewriteEngine on&lt;br /&gt;RewriteRule ^tutorials/(.*)/(.*)-([0-9]+)/?$ /tutorials.php?id=$3&amp;title=$2&amp;category=$1&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Take it apart!&lt;/b&gt;&lt;br /&gt;The first line: &lt;b&gt;RewriteEngine on&lt;/b&gt; simply does what it says, it starts the rewrite engine. &lt;br /&gt;Now let`s take apart the second line:&lt;br /&gt;&lt;div class="code"&gt;&lt;b&gt;RewriteRule&lt;/b&gt; - this tells the server about the rule to follow when rewriting the URL&lt;br /&gt;&lt;b&gt;^&lt;/b&gt; - this exponential sign means the start of the URL: http://www.mywebsite.com/&lt;br /&gt;&lt;b&gt;tutorials&lt;/b&gt; - this word is simply added to the website adress&lt;br /&gt;&lt;b&gt;/&lt;/b&gt; - this character separates the directories &lt;br /&gt;&lt;b&gt;(.*)&lt;/b&gt; - this tells the server that here will be placed some data (any kind of characters) (e.g.: php)&lt;br /&gt;&lt;b&gt;-&lt;/b&gt; - this character will be simply added to the website adress&lt;br /&gt;&lt;b&gt;([0-9])&lt;/b&gt; - this tells the server that here will be placed a digit (e.g: 1)&lt;br /&gt;&lt;b&gt;+&lt;/b&gt; - the plus sign tells the server that here can be more digits (e.g.: 123)&lt;br /&gt;&lt;b&gt;?&lt;/b&gt; - this sign tell the server that the character in it`s front it`s not required (so the URL will work with and without the last "/")&lt;br /&gt;&lt;b&gt;$&lt;/b&gt; - the dollar sign tells the server that here is the end of the rule&lt;/div&gt;The last part of the line is the old address, the value of each variable (id, title and category) are changed to $3, $2 and $1. mod_rewrite takes these variables and places them in their new position in the new URL. In the first place for data (the first (.*)) it places the $1`s value (the category value), in the second place the value of $2 and so on. If you want to change the order just change the $1, $2 and $3 order, but be careful to set the right data type in the new URL. &lt;br /&gt;&lt;br /&gt;I know that it`s not easy, if you have any question please don`t hesitate, ASK ME! And I will try to answer as fast as I can. You can for example write me in a comment your URL and how you want to transform it and I will try to make it ;)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4458784298246858128?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PuTz2sFFaJP_p3DATSdRo5pDxzQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PuTz2sFFaJP_p3DATSdRo5pDxzQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PuTz2sFFaJP_p3DATSdRo5pDxzQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PuTz2sFFaJP_p3DATSdRo5pDxzQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/THJxx8t1S9k" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-19T07:12:33.290-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total><feedburner:origLink>http://www.codingmix.com/2010/12/mod-rewrite-seo-url-php-htaccess.html</feedburner:origLink></item><item><title>My first AdSense payment arrived today!</title><link>http://feedproxy.google.com/~r/CodingMix/~3/dLTjabZh8xM/adsense-payment-check-first.html</link><category>Miscellaneous other</category><category>Miscellaneous</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 10 Dec 2010 12:55:27 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6663520962705863627</guid><description>I`m very happy, today my first AdSense payment has arrived. When I`we opened this website I wasn`t even sure if AdSense will send me the money if I reach the threshold. In the first 1 - 2 months it seems that I will never reach the 70€, but since that time my incomings are slowly increasing. I`we worked hard for this money but it worth it!&lt;br /&gt;I`we made an image about the check, bellow the check is my adsense pin:&lt;div id="full-post"&gt;&lt;img style="width: 550px; height: 413px;" src="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TQKNvhfg_9I/AAAAAAAAAQ4/QKVcH9ri_kw/s1600/adsense-payment.png" alt="first adsense payment check"/&gt;I know that 70€ is a small amount but I`m sure that I will get more checks like this or even with higher amount of money.&lt;br /&gt;&lt;br /&gt;Most of my traffic comes from tutorial sites and only a small percentage from google so I want to search engine optimize this website, this would bring more visitors, more visitors means more money and a larger community!&lt;br /&gt;&lt;br /&gt;Oh and Thanks for all of my visitors, you all have contributed to this!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6663520962705863627?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/veJqgWO2D74HfNd5qjWUzzkCeVQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/veJqgWO2D74HfNd5qjWUzzkCeVQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/veJqgWO2D74HfNd5qjWUzzkCeVQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/veJqgWO2D74HfNd5qjWUzzkCeVQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/dLTjabZh8xM" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-10T12:55:27.209-08:00</app:edited><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TQKNvhfg_9I/AAAAAAAAAQ4/QKVcH9ri_kw/s72-c/adsense-payment.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.codingmix.com/2010/12/adsense-payment-check-first.html</feedburner:origLink></item><item><title>My first 2D game in C++ using Direct3D</title><link>http://feedproxy.google.com/~r/CodingMix/~3/nzddpsqhEUU/2d-game-directx-snake-cplusplus.html</link><category>Cplusplus projects</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 10 Dec 2010 12:54:38 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5494779758440019457</guid><description>This is my first 2D game. It`s written in C++ using DirectX9 (Direct3D and DirectInput). This is a very simple Snake game. At the beginning the snake is only 1 square long and when it "eats" the target it`s length is encreased by 1 square. The snake can have a maximum of 20 squares long (each square is 20px), after it reaches this maximum length the snake is moving faster and faster. If the head of the snake hit`s it`s  tail the game is over:&lt;div id="full-post"&gt;&lt;object width="540" height="328"&gt;&lt;param name="movie" value="http://www.youtube.com/v/K8_UpmEfEnU?fs=1&amp;amp;hl=en_US&amp;amp;rel=0&amp;amp;color1=0x234900&amp;amp;color2=0x4e9e00"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/K8_UpmEfEnU?fs=1&amp;amp;hl=en_US&amp;amp;rel=0&amp;amp;color1=0x234900&amp;amp;color2=0x4e9e00" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="540" height="328"&gt;&lt;/embed&gt;&lt;/object&gt;And here is the source-code:&lt;div class="code"&gt;#include &amp;lt;Windows.h&amp;gt;&lt;br /&gt;#include &amp;lt;WindowsX.h&amp;gt;&lt;br /&gt;#include &amp;lt;d3d9.h&amp;gt;&lt;br /&gt;#include &amp;lt;d3dx9.h&amp;gt;&lt;br /&gt;#include &amp;lt;dinput.h&amp;gt;&lt;br /&gt;#include &amp;lt;ctime&amp;gt;&lt;br /&gt;&lt;br /&gt;#pragma comment(lib,&amp;quot;d3d9.lib&amp;quot;);&lt;br /&gt;#pragma comment(lib,&amp;quot;d3dx9.lib&amp;quot;);&lt;br /&gt;#pragma comment(lib,&amp;quot;dinput8.lib&amp;quot;);&lt;br /&gt;#pragma comment(lib,&amp;quot;dxguid.lib&amp;quot;);&lt;br /&gt;&lt;br /&gt;LPDIRECT3D9 d3d;&lt;br /&gt;LPDIRECT3DDEVICE9 d3ddev;&lt;br /&gt;LPDIRECT3DVERTEXBUFFER9 buffer=NULL;&lt;br /&gt;LPDIRECTINPUT8 dinput;&lt;br /&gt;LPDIRECTINPUTDEVICE8 keyboard;&lt;br /&gt;BYTE buttons[256];&lt;br /&gt;ID3DXFont *m_font;&lt;br /&gt;&lt;br /&gt;LRESULT CALLBACK WindowProc(HWND hWnd,&lt;br /&gt;                                                             UINT message,&lt;br /&gt;                                                             WPARAM wParam,&lt;br /&gt;                                                             LPARAM lParam);&lt;br /&gt;void initialized3d(HWND hWnd);&lt;br /&gt;void renderframe(void);&lt;br /&gt;void cleand3d(void);&lt;br /&gt;void graphics(void);&lt;br /&gt;void initializedinput(HINSTANCE hInstance,&lt;br /&gt;                             HWND hWnd);&lt;br /&gt;void getkey(void);&lt;br /&gt;void cleandinput(void);&lt;br /&gt;&lt;br /&gt;struct VERTEX {&lt;br /&gt;   FLOAT X, Y, Z, RHW; &lt;br /&gt;   DWORD COLOR;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#define FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)&lt;br /&gt;&lt;br /&gt;int WINAPI WinMain(HINSTANCE hInstance, &lt;br /&gt;                                   HINSTANCE hPrevInstance, &lt;br /&gt;                                   LPSTR lpCmdLine,&lt;br /&gt;                                   int nCmdShow){&lt;br /&gt;   WNDCLASSEX windowclass;&lt;br /&gt;   ZeroMemory(&amp;amp;windowclass,sizeof(WNDCLASSEX));&lt;br /&gt;&lt;br /&gt;   windowclass.cbSize = sizeof(WNDCLASSEX);&lt;br /&gt;   windowclass.style = CS_HREDRAW | CS_VREDRAW;&lt;br /&gt;   windowclass.lpfnWndProc = WindowProc;&lt;br /&gt;   windowclass.hInstance = hInstance;&lt;br /&gt;   windowclass.hCursor = LoadCursor(NULL,IDC_ARROW);&lt;br /&gt;   windowclass.hbrBackground = (HBRUSH)COLOR_WINDOW;&lt;br /&gt;   windowclass.lpszClassName = L&amp;quot;WindowClass&amp;quot;;&lt;br /&gt;&lt;br /&gt;   RegisterClassEx(&amp;amp;windowclass);&lt;br /&gt;   HWND hWnd = CreateWindowEx(NULL,&lt;br /&gt;                                                          L&amp;quot;WindowClass&amp;quot;,&lt;br /&gt;                                                          L&amp;quot;Snake - www.codingmix.com&amp;quot;,&lt;br /&gt;                                                          WS_OVERLAPPEDWINDOW,&lt;br /&gt;                                                          600,&lt;br /&gt;                                                          200,&lt;br /&gt;                                                          636,&lt;br /&gt;                                                          478,&lt;br /&gt;                                                          NULL,&lt;br /&gt;                                                          NULL,&lt;br /&gt;                                                          hInstance,&lt;br /&gt;                                                          NULL);&lt;br /&gt;   ShowWindow(hWnd,&lt;br /&gt;                          nCmdShow);&lt;br /&gt;   initialized3d(hWnd);&lt;br /&gt;   initializedinput(hInstance,&lt;br /&gt;                         hWnd);&lt;br /&gt;   MSG message;&lt;br /&gt;   while(TRUE){&lt;br /&gt;      while(PeekMessage(&amp;amp;message,&lt;br /&gt;                                      NULL,&lt;br /&gt;                                      0,&lt;br /&gt;                                      0,&lt;br /&gt;                                      PM_REMOVE)){&lt;br /&gt;         TranslateMessage(&amp;amp;message);&lt;br /&gt;         DispatchMessage(&amp;amp;message);&lt;br /&gt;      }&lt;br /&gt;      if(message.message == WM_QUIT){&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      getkey();&lt;br /&gt;      graphics();&lt;br /&gt;      renderframe();&lt;br /&gt;   }  &lt;br /&gt;   cleand3d();&lt;br /&gt;   cleandinput();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void initialized3d(HWND hWnd){&lt;br /&gt;   d3d = Direct3DCreate9(D3D_SDK_VERSION);&lt;br /&gt;   D3DPRESENT_PARAMETERS d3dpp;&lt;br /&gt;   ZeroMemory(&amp;amp;d3dpp,sizeof(d3dpp));&lt;br /&gt;&lt;br /&gt;   d3dpp.Windowed = TRUE;&lt;br /&gt;   d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;&lt;br /&gt;   d3dpp.hDeviceWindow = hWnd;&lt;br /&gt;&lt;br /&gt;   d3d-&amp;gt;CreateDevice(D3DADAPTER_DEFAULT,&lt;br /&gt;                                   D3DDEVTYPE_HAL,&lt;br /&gt;                                   hWnd,&lt;br /&gt;                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING,&lt;br /&gt;                                   &amp;amp;d3dpp,&lt;br /&gt;                                   &amp;amp;d3ddev);&lt;br /&gt;   D3DXCreateFont(d3ddev, &lt;br /&gt;                                50, &lt;br /&gt;                                0, &lt;br /&gt;                                FW_BOLD, &lt;br /&gt;                                0, &lt;br /&gt;                                FALSE, &lt;br /&gt;                                DEFAULT_CHARSET, &lt;br /&gt;                                OUT_DEFAULT_PRECIS, &lt;br /&gt;                                DEFAULT_QUALITY, &lt;br /&gt;                                DEFAULT_PITCH | FF_DONTCARE, &lt;br /&gt;                                TEXT(&amp;quot;Arial&amp;quot;), &lt;br /&gt;                                &amp;amp;m_font );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void initializedinput(HINSTANCE hInstance,&lt;br /&gt;                              HWND hWnd){&lt;br /&gt;   DirectInput8Create(hInstance,&lt;br /&gt;                                 DIRECTINPUT_VERSION,&lt;br /&gt;                                 IID_IDirectInput8,&lt;br /&gt;                                 (void**)&amp;amp;dinput,&lt;br /&gt;                                 NULL);&lt;br /&gt;   dinput-&amp;gt;CreateDevice(GUID_SysKeyboard,&lt;br /&gt;                                      &amp;amp;keyboard,&lt;br /&gt;                                      NULL);&lt;br /&gt;   keyboard-&amp;gt;SetDataFormat(&amp;amp;c_dfDIKeyboard);&lt;br /&gt;   keyboard-&amp;gt;SetCooperativeLevel(hWnd,&lt;br /&gt;                                                      DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int verticesnr = 132;&lt;br /&gt;int trianglesnr = 44;&lt;br /&gt;bool left = false;&lt;br /&gt;bool right = false;&lt;br /&gt;bool up = true;&lt;br /&gt;bool down = false;&lt;br /&gt;float posy = 220.0f;&lt;br /&gt;float posx = 280.0f;&lt;br /&gt;bool target = false;&lt;br /&gt;float random1;&lt;br /&gt;float random2;&lt;br /&gt;float newpos[][2] = {&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;   {-20.0f, -20.0f},&lt;br /&gt;};&lt;br /&gt;int squares = 0;&lt;br /&gt;bool gameover = false;&lt;br /&gt;int col1 = 0;&lt;br /&gt;int col2 = 255;&lt;br /&gt;int currentframe = 0;&lt;br /&gt;int speed = 30;&lt;br /&gt;void graphics(void){&lt;br /&gt;   static int framenr = 0;&lt;br /&gt;   framenr++;&lt;br /&gt;   if(framenr % speed == 0 &amp;amp;&amp;amp; !gameover){&lt;br /&gt;      if(squares &amp;gt; 0){&lt;br /&gt;         for(int i=squares-1;i&amp;gt;0;i--){&lt;br /&gt;            newpos[i][0] = newpos[i-1][0];&lt;br /&gt;            newpos[i][1] = newpos[i-1][1];&lt;br /&gt;         } &lt;br /&gt;         newpos[0][0] = posx;&lt;br /&gt;         newpos[0][1] = posy;&lt;br /&gt;      }&lt;br /&gt;      if(up){&lt;br /&gt;         posy -= 20.0f;&lt;br /&gt;      }&lt;br /&gt;      else if(down){&lt;br /&gt;         posy += 20.0f;&lt;br /&gt;      }&lt;br /&gt;      else if(left){&lt;br /&gt;         posx -= 20.0f;&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         posx += 20.0f;&lt;br /&gt;      }&lt;br /&gt;      for(int i=0;i&amp;lt;=squares;i++){&lt;br /&gt;         for(int y=0;y&amp;lt;=squares;y++){&lt;br /&gt;            if(newpos[i][0] == newpos[y][0] &amp;amp;&amp;amp; newpos[i][1] == newpos[y][1] &amp;amp;&amp;amp; i != y){&lt;br /&gt;               gameover = true;&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         if(posx == newpos[i][0] &amp;amp;&amp;amp; posy == newpos[i][1]){&lt;br /&gt;            gameover = true;&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      if(posx == random1 &amp;amp;&amp;amp; posy == random2){&lt;br /&gt;         target = false;&lt;br /&gt;         if(squares &amp;gt; 19 &amp;amp;&amp;amp; squares &amp;gt; 0){&lt;br /&gt;            speed--;&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            if(squares == 0){&lt;br /&gt;               newpos[0][0] = posx;&lt;br /&gt;               newpos[0][1] = posy;&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               newpos[squares][0] = newpos[squares-1][0];&lt;br /&gt;               newpos[squares][1] = newpos[squares-1][1];&lt;br /&gt;            }&lt;br /&gt;            squares++;&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      for(int i=0;i&amp;lt;squares;i++){&lt;br /&gt;         if(newpos[i][0] &amp;gt; 600){&lt;br /&gt;            newpos[i][0]-=620;&lt;br /&gt;         }&lt;br /&gt;         else if(newpos[i][0] &amp;lt; 0){&lt;br /&gt;            newpos[i][0]+=620;&lt;br /&gt;         }&lt;br /&gt;         else if(newpos[i][1] &amp;gt; 420){&lt;br /&gt;            newpos[i][1]-=440;&lt;br /&gt;         }&lt;br /&gt;         else if(newpos[i][1] &amp;lt; 0){&lt;br /&gt;            newpos[i][1]+=440;&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      if(posx &amp;gt; 600){&lt;br /&gt;         posx-=620;&lt;br /&gt;      }&lt;br /&gt;      else if(posx &amp;lt; 0){&lt;br /&gt;         posx+=620;&lt;br /&gt;      }&lt;br /&gt;      else if(posy &amp;gt; 420){&lt;br /&gt;         posy-=440;&lt;br /&gt;      }&lt;br /&gt;      else if(posy &amp;lt; 0){&lt;br /&gt;         posy+=440;&lt;br /&gt;      }&lt;br /&gt;      currentframe = 0;&lt;br /&gt;   }&lt;br /&gt;   else if(framenr % 20 == 0 &amp;amp;&amp;amp; gameover){&lt;br /&gt;      if(col1 == 255){&lt;br /&gt;         col1 = 0;&lt;br /&gt;         col2 = 255;&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         col1 = 255;&lt;br /&gt;         col2 = 0;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   if(buttons[DIK_LEFT] &amp;amp; 0x80 &amp;amp;&amp;amp; right == false &amp;amp;&amp;amp; currentframe == 0){&lt;br /&gt;      left = true;&lt;br /&gt;      up = false;&lt;br /&gt;      down = false;&lt;br /&gt;      currentframe = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(buttons[DIK_RIGHT] &amp;amp; 0x80 &amp;amp;&amp;amp; left == false &amp;amp;&amp;amp; currentframe == 0){&lt;br /&gt;      right = true;&lt;br /&gt;      up = false;&lt;br /&gt;      down = false;&lt;br /&gt;      currentframe = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(buttons[DIK_UP] &amp;amp; 0x80 &amp;amp;&amp;amp; down == false &amp;amp;&amp;amp; currentframe == 0){&lt;br /&gt;      up = true;&lt;br /&gt;      left = false;&lt;br /&gt;      right = false;&lt;br /&gt;      currentframe = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(buttons[DIK_DOWN] &amp;amp; 0x80 &amp;amp;&amp;amp; up == false &amp;amp;&amp;amp; currentframe == 0){&lt;br /&gt;      down = true;&lt;br /&gt;      left = false;&lt;br /&gt;      right = false;&lt;br /&gt;      currentframe = 1;&lt;br /&gt;   }&lt;br /&gt;   if(!target){&lt;br /&gt;      srand((unsigned)time(0));&lt;br /&gt;      random1 = (rand() % 30) * 20.0f; &lt;br /&gt;      random2 = (rand() % 22) * 20.0f;&lt;br /&gt;      target = true;&lt;br /&gt;   }&lt;br /&gt;   VERTEX vertices[] = {&lt;br /&gt;      //Target&lt;br /&gt;      {random1 + 10.0f, random2, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),},&lt;br /&gt;      {random1 + 20.0f, random2 + 10.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),},&lt;br /&gt;      {random1, random2 + 10.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),},&lt;br /&gt;      {random1, random2 + 10.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),},&lt;br /&gt;      {random1 + 20.0f, random2 + 10.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),},&lt;br /&gt;      {random1 + 10.0f, random2 + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),},&lt;br /&gt;      //Head&lt;br /&gt;      {posx , posy, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {posx + 20.0f, posy, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {posx, posy + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {posx, posy + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {posx + 20.0f, posy, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {posx + 20.0f, posy + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 1&lt;br /&gt;      {newpos[0][0] , newpos[0][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[0][0] + 20.0f, newpos[0][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[0][0], newpos[0][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[0][0], newpos[0][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[0][0] + 20.0f, newpos[0][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[0][0] + 20.0f, newpos[0][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 2&lt;br /&gt;      {newpos[1][0] , newpos[1][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[1][0] + 20.0f, newpos[1][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[1][0], newpos[1][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[1][0], newpos[1][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[1][0] + 20.0f, newpos[1][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[1][0] + 20.0f, newpos[1][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 3&lt;br /&gt;      {newpos[2][0] , newpos[2][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[2][0] + 20.0f, newpos[2][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[2][0], newpos[2][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[2][0], newpos[2][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[2][0] + 20.0f, newpos[2][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[2][0] + 20.0f, newpos[2][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 4&lt;br /&gt;      {newpos[3][0] , newpos[3][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[3][0] + 20.0f, newpos[3][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[3][0], newpos[3][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[3][0], newpos[3][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[3][0] + 20.0f, newpos[3][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[3][0] + 20.0f, newpos[3][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 5&lt;br /&gt;      {newpos[4][0] , newpos[4][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[4][0] + 20.0f, newpos[4][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[4][0], newpos[4][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[4][0], newpos[4][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[4][0] + 20.0f, newpos[4][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[4][0] + 20.0f, newpos[4][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 6&lt;br /&gt;      {newpos[5][0] , newpos[5][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[5][0] + 20.0f, newpos[5][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[5][0], newpos[5][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[5][0], newpos[5][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[5][0] + 20.0f, newpos[5][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[5][0] + 20.0f, newpos[5][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 7&lt;br /&gt;      {newpos[6][0] , newpos[6][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[6][0] + 20.0f, newpos[6][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[6][0], newpos[6][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[6][0], newpos[6][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[6][0] + 20.0f, newpos[6][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[6][0] + 20.0f, newpos[6][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 8&lt;br /&gt;      {newpos[7][0] , newpos[7][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[7][0] + 20.0f, newpos[7][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[7][0], newpos[7][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[7][0], newpos[7][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[7][0] + 20.0f, newpos[7][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[7][0] + 20.0f, newpos[7][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 9&lt;br /&gt;      {newpos[8][0] , newpos[8][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[8][0] + 20.0f, newpos[8][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[8][0], newpos[8][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[8][0], newpos[8][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[8][0] + 20.0f, newpos[8][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[8][0] + 20.0f, newpos[8][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 10&lt;br /&gt;      {newpos[9][0] , newpos[9][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[9][0] + 20.0f, newpos[9][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[9][0], newpos[9][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[9][0], newpos[9][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[9][0] + 20.0f, newpos[9][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[9][0] + 20.0f, newpos[9][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 11&lt;br /&gt;      {newpos[10][0] , newpos[10][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[10][0] + 20.0f, newpos[10][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[10][0], newpos[10][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[10][0], newpos[10][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[10][0] + 20.0f, newpos[10][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[10][0] + 20.0f, newpos[10][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 12&lt;br /&gt;      {newpos[11][0] , newpos[11][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[11][0] + 20.0f, newpos[11][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[11][0], newpos[11][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[11][0], newpos[11][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[11][0] + 20.0f, newpos[11][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[11][0] + 20.0f, newpos[11][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 13&lt;br /&gt;      {newpos[12][0] , newpos[12][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[12][0] + 20.0f, newpos[12][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[12][0], newpos[12][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[12][0], newpos[12][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[12][0] + 20.0f, newpos[12][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[12][0] + 20.0f, newpos[12][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 14&lt;br /&gt;      {newpos[13][0] , newpos[13][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[13][0] + 20.0f, newpos[13][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[13][0], newpos[13][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[13][0], newpos[13][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[13][0] + 20.0f, newpos[13][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[13][0] + 20.0f, newpos[13][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 15&lt;br /&gt;      {newpos[14][0] , newpos[14][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[14][0] + 20.0f, newpos[14][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[14][0], newpos[14][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[14][0], newpos[14][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[14][0] + 20.0f, newpos[14][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[14][0] + 20.0f, newpos[14][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 16&lt;br /&gt;      {newpos[15][0] , newpos[15][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[15][0] + 20.0f, newpos[15][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[15][0], newpos[15][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[15][0], newpos[15][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[15][0] + 20.0f, newpos[15][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[15][0] + 20.0f, newpos[15][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 17&lt;br /&gt;      {newpos[16][0] , newpos[16][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[16][0] + 20.0f, newpos[16][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[16][0], newpos[16][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[16][0], newpos[16][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[16][0] + 20.0f, newpos[16][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[16][0] + 20.0f, newpos[16][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 18&lt;br /&gt;      {newpos[17][0] , newpos[17][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[17][0] + 20.0f, newpos[17][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[17][0], newpos[17][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[17][0], newpos[17][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[17][0] + 20.0f, newpos[17][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[17][0] + 20.0f, newpos[17][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 19&lt;br /&gt;      {newpos[18][0] , newpos[18][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[18][0] + 20.0f, newpos[18][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[18][0], newpos[18][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[18][0], newpos[18][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[18][0] + 20.0f, newpos[18][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[18][0] + 20.0f, newpos[18][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      //Square 20&lt;br /&gt;      {newpos[19][0] , newpos[19][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[19][0] + 20.0f, newpos[19][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[19][0], newpos[19][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[19][0], newpos[19][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[19][0] + 20.0f, newpos[19][1], 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;      {newpos[19][0] + 20.0f, newpos[19][1] + 20.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(col1, col2, 0),},&lt;br /&gt;   };&lt;br /&gt;   d3ddev-&amp;gt;CreateVertexBuffer(verticesnr*sizeof(VERTEX),&lt;br /&gt;                                                 0,&lt;br /&gt;                                                 FVF,&lt;br /&gt;                                                 D3DPOOL_MANAGED,&lt;br /&gt;                                                 &amp;amp;buffer,&lt;br /&gt;                                                 NULL);&lt;br /&gt;   VOID* pVoid;&lt;br /&gt;   buffer-&amp;gt;Lock(0,&lt;br /&gt;                         0,&lt;br /&gt;                         (void**)&amp;amp;pVoid,&lt;br /&gt;                         0);&lt;br /&gt;   memcpy(pVoid,&lt;br /&gt;                 vertices,&lt;br /&gt;                 sizeof(vertices));&lt;br /&gt;   buffer-&amp;gt;Unlock();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void getkey(void){&lt;br /&gt;   keyboard-&amp;gt;Acquire();&lt;br /&gt;   keyboard-&amp;gt;GetDeviceState(256,&lt;br /&gt;                                              (LPVOID)buttons);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void renderframe(void){&lt;br /&gt;   d3ddev-&amp;gt;Clear(0,&lt;br /&gt;                            NULL,&lt;br /&gt;                            D3DCLEAR_TARGET,&lt;br /&gt;                            D3DCOLOR_XRGB(255,222,173),&lt;br /&gt;                            1.0f,&lt;br /&gt;                            0);&lt;br /&gt;   d3ddev-&amp;gt;BeginScene();&lt;br /&gt;&lt;br /&gt;   D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,0,0); &lt;br /&gt;   RECT rct;&lt;br /&gt;   rct.left=200;&lt;br /&gt;   rct.right=480;&lt;br /&gt;   rct.top=150;&lt;br /&gt;   rct.bottom=rct.top+50;&lt;br /&gt;   if(gameover){&lt;br /&gt;      m_font-&amp;gt;DrawText(NULL,&lt;br /&gt;                                     (LPCWSTR)L&amp;quot;Game over&amp;quot;,&lt;br /&gt;                                     -1,&lt;br /&gt;                                     &amp;amp;rct,&lt;br /&gt;                                     0,&lt;br /&gt;                                     fontColor);&lt;br /&gt;   }&lt;br /&gt;   d3ddev-&amp;gt;SetFVF(FVF);&lt;br /&gt;   d3ddev-&amp;gt;SetStreamSource(0,&lt;br /&gt;                                              buffer,&lt;br /&gt;                                              0,&lt;br /&gt;                                              sizeof(VERTEX));&lt;br /&gt;   d3ddev-&amp;gt;DrawPrimitive(D3DPT_TRIANGLELIST,&lt;br /&gt;                                         0,&lt;br /&gt;                                         trianglesnr);&lt;br /&gt;   d3ddev-&amp;gt;EndScene();&lt;br /&gt;   d3ddev-&amp;gt;Present(NULL,&lt;br /&gt;                               NULL,&lt;br /&gt;                               NULL,&lt;br /&gt;                               NULL);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void cleand3d(void){&lt;br /&gt;   buffer-&amp;gt;Release();&lt;br /&gt;   d3ddev-&amp;gt;Release();&lt;br /&gt;   d3d-&amp;gt;Release();&lt;br /&gt;   m_font-&amp;gt;Release();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void cleandinput(void){&lt;br /&gt;   keyboard-&amp;gt;Unacquire(); &lt;br /&gt;   dinput-&amp;gt;Release(); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;LRESULT CALLBACK WindowProc(HWND hWnd,&lt;br /&gt;                                                             UINT message,&lt;br /&gt;                                                             WPARAM wParam,&lt;br /&gt;                                                             LPARAM lParam){&lt;br /&gt;   if(message == WM_DESTROY){&lt;br /&gt;      PostQuitMessage(0);&lt;br /&gt;      return 0;&lt;br /&gt;   }&lt;br /&gt;   return DefWindowProc(hWnd,&lt;br /&gt;                                        message,&lt;br /&gt;                                        wParam,&lt;br /&gt;                                        lParam);&lt;br /&gt;}&lt;/div&gt;You can ask anything about how it works but I`m just a beginner in DirectX programming...&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5494779758440019457?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ztV6MMYrbGNlZc-lDCuVilK-bSM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ztV6MMYrbGNlZc-lDCuVilK-bSM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ztV6MMYrbGNlZc-lDCuVilK-bSM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ztV6MMYrbGNlZc-lDCuVilK-bSM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/nzddpsqhEUU" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-10T12:54:38.013-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">12</thr:total><enclosure url="http://www.youtube.com/v/K8_UpmEfEnU?fs=1&amp;amp;hl=en_US&amp;amp;rel=0&amp;amp;color1=0x234900&amp;amp;color2=0x4e9e00" length="1087" type="application/x-shockwave-flash" /><feedburner:origLink>http://www.codingmix.com/2010/12/2d-game-directx-snake-cplusplus.html</feedburner:origLink></item><item><title>Addition with extremely huge numbers in C++</title><link>http://feedproxy.google.com/~r/CodingMix/~3/oqQeMw4Op6M/addition-with-extremely-huge-numbers-in.html</link><category>Cplusplus projects</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 03 Dec 2010 11:40:56 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-7400027607781102421</guid><description>In C++ you the data type with the largest range is the &lt;i&gt;long long&lt;/i&gt;, with a maximum limit of ~19 digits. This means that you can`t make additions with numbers that result a larger number. I know this is a crazy thing, why would you need to calculate with such huge numbers ? I think never..., but the method is very useful and ingenious. &lt;div id="full-post"&gt;Here is my code:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   string nr; &lt;br /&gt;   bool validnr = false;&lt;br /&gt;   while(!validnr){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;Enter the first number: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      cin &amp;gt;&amp;gt; nr;&lt;br /&gt;      validnr = true;&lt;br /&gt;      &lt;span style="color:green;"&gt;//Check the number for invalid characters&lt;/span&gt;&lt;br /&gt;      for(int i=0;i&amp;lt;nr.length();i++){&lt;br /&gt;         if((int) nr[i] &amp;lt; 48 || (int) nr[i] &amp;gt; 57){&lt;br /&gt;            &lt;span style="color:green;"&gt;//48 is the ASCII code of number 0&lt;/span&gt;&lt;br /&gt;            &lt;span style="color:green;"&gt;//57 is the ASCII code of number 9&lt;/span&gt;&lt;br /&gt;            validnr = false; &lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      if(!validnr){&lt;br /&gt;         cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Please enter a valid number!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   string nr2;&lt;br /&gt;   validnr = false;&lt;br /&gt;   &lt;span style="color:green;"&gt;//Do the same for the second number&lt;/span&gt;&lt;br /&gt;   while(!validnr){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;Enter the second number: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      cin &amp;gt;&amp;gt; nr2;&lt;br /&gt;      validnr = true;&lt;br /&gt;      for(int i=0;i&amp;lt;nr2.length();i++){&lt;br /&gt;         if((int) nr2[i] &amp;lt; 48 || (int) nr2[i] &amp;gt; 57){&lt;br /&gt;            validnr = false; &lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      if(!validnr){&lt;br /&gt;         cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Please enter a valid number!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   int digitsnr;&lt;br /&gt;   &lt;span style="color:green;"&gt;//Make the two digits to have the same size&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;//by adding 0`s in front of it&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;//This is important because we can`t add a digit with nothing&lt;/span&gt;&lt;br /&gt;   if(nr.length() &amp;gt; nr2.length()){&lt;br /&gt;      digitsnr = nr.length() - 1;&lt;br /&gt;      while(nr.length() != nr2.length()){&lt;br /&gt;         nr2 = &amp;quot;0&amp;quot; + nr2;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      digitsnr = nr2.length() - 1;&lt;br /&gt;      while(nr.length() != nr2.length()){&lt;br /&gt;         nr = &amp;quot;0&amp;quot; + nr;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   string result;&lt;br /&gt;   char digit;&lt;br /&gt;   int remainder = 0; &lt;span style="color:green;"&gt;//If the result of two digits is more than 10&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;//we need to add 1 to the following digit(e.g: 5 + 7 = 12, 12 is made from 2 digits&lt;/span&gt; &lt;br /&gt;   for(int i=digitsnr;i&amp;gt;=0;i--){ &lt;span style="color:green;"&gt;//Loop through each digit&lt;/span&gt;&lt;br /&gt;      if(remainder + nr[i] + nr2[i] - 96 &amp;gt; 9){&lt;br /&gt;         digit = remainder + nr[i] + nr2[i] - 48 - 10; &lt;span style="color:green;"&gt;//We are working with ASCII codes&lt;/span&gt;&lt;br /&gt;         result = digit + result;&lt;br /&gt;         remainder = 1; &lt;span style="color:green;"&gt;//We have to increase the following digit&lt;/span&gt;&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         digit = remainder + nr[i] + nr2[i] - 48;&lt;br /&gt;         remainder = 0;&lt;br /&gt;         result = digit + result;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   if(remainder){&lt;br /&gt;      result = &amp;quot;1&amp;quot; + result; &lt;br /&gt;     &lt;span style="color:green;"&gt;//Add the last remaining if required&lt;/span&gt;&lt;br /&gt;   }&lt;br /&gt;   cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Result = &amp;quot; &amp;lt;&amp;lt; result &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;The numbers are stored in strings, each character of the strings is checked to avoid wrong characters. Each character is checked using it`s ASCII code, (for example 0 has the 47 code number, 1 has the 49 code). After the numbers are validated the two numbers are added digit by digit starting from the last number:&lt;div class="code"&gt;123 + 56 = &lt;br /&gt;9&lt;br /&gt;79&lt;br /&gt;179&lt;/div&gt;Is that simple, but if something it`s not clear please don`t hesitate, ASK ME!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-7400027607781102421?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rDZLvUISG-XLMz3DSI2lov8DCHE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rDZLvUISG-XLMz3DSI2lov8DCHE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rDZLvUISG-XLMz3DSI2lov8DCHE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rDZLvUISG-XLMz3DSI2lov8DCHE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/oqQeMw4Op6M" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-03T11:40:56.423-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total><feedburner:origLink>http://www.codingmix.com/2010/12/addition-with-extremely-huge-numbers-in.html</feedburner:origLink></item><item><title>Simple Chat script in PHP and jQuery</title><link>http://feedproxy.google.com/~r/CodingMix/~3/PNyWtrvhoiQ/chat-php-jquery.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 22 Nov 2010 05:48:54 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6993358900270163961</guid><description>This is a very basic Chat script written in PHP and jQuery for more browser compatibility. The script saves the messages in a MySQL table and automatically removes the old messages, so it needs minimum disk space. If you prefer Javascript instead, check out this version of the &lt;a href="http://www.codingmix.com/2010/11/cross-browser-chat-script-using-php.html" title="chat"&gt;chat script&lt;/a&gt;. Here is a live demo:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/jchat/chat.php" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;&lt;br /&gt;The script first needs a MySQL table:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;mysql_connect('host', 'database', 'password') &lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_query(&amp;quot;create table chat(&lt;br /&gt;   time int(11) NOT NULL, &lt;br /&gt;   name varchar(30) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   message varchar(255) NOT NULL, &lt;br /&gt;   PRIMARY KEY (time)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Than we need the main page of the script:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.message {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:498px;&lt;br /&gt;   margin-bottom:5px;&lt;br /&gt;   border:1px solid #999;&lt;br /&gt;}&lt;br /&gt;.messagehead {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#FFC;&lt;br /&gt;   width:500px;&lt;br /&gt;}&lt;br /&gt;.messagecontent {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:496px;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//Include jQuery&lt;/span&gt;&lt;br /&gt;&amp;lt;script src=&amp;quot;http://code.jquery.com/jquery-latest.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;width:500px;margin:0 auto;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;error&amp;quot; style=&amp;quot;width:500px;text-align:center;color:red;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;write&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&amp;gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;Name:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; id=&amp;quot;sendbutton&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function showmessages(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Change the content of the &lt;i&gt;messages&lt;/i&gt; div with the response from the &lt;i&gt;show-messages.php&lt;/i&gt; file.&lt;/span&gt;&lt;br /&gt;   $('#messages').html($.ajax({&lt;br /&gt;      url: 'show-messages.php?x=' + Math.random(), &lt;span style="color:green;"&gt;//The URL is always unique because of the random number&lt;/span&gt;&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText);&lt;br /&gt;   &lt;span style="color:green;"&gt;//Repeat the function each 30 seconds&lt;/span&gt;&lt;br /&gt;   setTimeout('showmessages()',30000); &lt;br /&gt;}&lt;br /&gt;showmessages();&lt;br /&gt;$('#sendbutton').click(function(){&lt;br /&gt;   var error = ''; &lt;br /&gt;   &lt;span style="color:green;"&gt;//Show an error message based on the response from &lt;i&gt;send.php&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;   switch(parseInt($.ajax({&lt;br /&gt;      url: 'send.php?message=' + $('#message').val() + '&amp;amp;name=' + $('#name').val(),&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText)){&lt;br /&gt;   case 1:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      error = 'Don`t forget the message!';&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      error = 'The message is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 5:&lt;br /&gt;      error = 'Don`t forget the name!';&lt;br /&gt;      break;&lt;br /&gt;   case 6:&lt;br /&gt;      error = 'The name is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 7:&lt;br /&gt;      error = 'This name is already used by somebody else!';&lt;br /&gt;      break;&lt;br /&gt;   case 8:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;   }&lt;br /&gt;   if(error == ''){&lt;br /&gt;      $('#error').html('');&lt;br /&gt;      showmessages();&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      $('#error').html(error);&lt;br /&gt;   }&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;Now we need to create the file that saves the message:&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (1);&lt;br /&gt;mysql_select_db('database') or die (2);&lt;br /&gt;if(strlen($message) &amp;lt; 1){&lt;br /&gt;   echo 3;&lt;br /&gt;}&lt;br /&gt;else if(strlen($message) &amp;gt; 255){&lt;br /&gt;   echo 4;&lt;br /&gt;}&lt;br /&gt;else if(strlen($name) &amp;lt; 1){&lt;br /&gt;   echo 5;&lt;br /&gt;}&lt;br /&gt;else if(strlen($name) &amp;gt; 29){&lt;br /&gt;   echo 6;&lt;br /&gt;}&lt;br /&gt;else if(mysql_num_rows(mysql_query(&amp;quot;select * from chat where name = '&amp;quot; . $name . &amp;quot;' and ip != '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 7;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//Insert the new message in the table and remove the unwanted characters&lt;/span&gt;&lt;br /&gt;   $search = array(&amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;,&amp;quot;&amp;amp;lt;&amp;quot;);&lt;br /&gt;mysql_query(&amp;quot;insert into chat values ('&amp;quot; . time() . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$name) . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$message) . &amp;quot;')&amp;quot;) or die(8);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;And the file that sends back the messages to us:&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;mysql_select_db('database') or die(2);&lt;br /&gt;$result = mysql_query(&amp;quot;select * from chat order by time desc limit 0,10&amp;quot;);&lt;br /&gt;$messages = array();&lt;br /&gt;$i = 0;&lt;br /&gt;while($row = mysql_fetch_array($result)){ &lt;br /&gt;   $messages[$i] = &amp;quot;&amp;lt;div class='message'&amp;gt;&amp;lt;div class='messagehead'&amp;gt;&amp;quot; . $row[name] . &amp;quot; - &amp;quot;;&lt;br /&gt;   $timeago = time() - $row['time'];&lt;br /&gt;   &lt;span style="color:green;"&gt;//Calculate the message date&lt;/span&gt;&lt;br /&gt;   if($timeago &amp;gt; 86400){&lt;br /&gt;      $messages[$i] .= date('g:i A M, d Y',$row[time]);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      $hours = floor($timeago / 3600); &lt;br /&gt;      $minutes = floor(($timeago - ($hours * 3600)) / 60);&lt;br /&gt;      $seconds = floor($timeago - ($hours * 3600) - ($minutes * 60));&lt;br /&gt;      if($hours &amp;gt; 0){&lt;br /&gt;         if($minutes &amp;gt; 9){&lt;br /&gt;            if($seconds &amp;gt; 9){&lt;br /&gt;               $messages[$i] .= $hours . ' h, ' . $minutes . ' min, ' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               $messages[$i] .= $hours . ' h, ' . $minutes . ' min, 0' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            if($seconds &amp;gt; 9){&lt;br /&gt;               $messages[$i] .= $hours . ' h, 0' . $minutes . ' min, ' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               $messages[$i] .= $hours . ' h, 0' . $minutes . ' min, 0' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      else if($minutes &amp;gt; 0){&lt;br /&gt;         if($seconds &amp;gt; 9){&lt;br /&gt;            $messages[$i] .= $minutes . ' min, ' . $seconds . ' sec';&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            $messages[$i] .= $minutes . ' min, 0' . $seconds . ' sec';&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         $messages[$i] .= $seconds . ' sec';&lt;br /&gt;      }&lt;br /&gt;      $messages[$i] .= ' ago';&lt;br /&gt;   }&lt;br /&gt;   $messages[$i] .= &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='messagecontent'&amp;gt;&amp;quot; . $row[message] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;   $old = $row[time];&lt;br /&gt;   $i++;&lt;br /&gt;}&lt;br /&gt;for($i=9;$i&amp;gt;=0;$i--){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Output the messages from the oldest to the newest&lt;/span&gt;&lt;br /&gt;   echo $messages[$i];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Delete old messages&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;delete from chat where time &amp;lt; &amp;quot; . $old);&lt;br /&gt;?&amp;gt;&lt;/div&gt;If you have any related questions or problems please ask me!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6993358900270163961?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/IMkZRic_yryVXWfhV1wZfQmrWCM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IMkZRic_yryVXWfhV1wZfQmrWCM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/IMkZRic_yryVXWfhV1wZfQmrWCM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IMkZRic_yryVXWfhV1wZfQmrWCM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/PNyWtrvhoiQ" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-22T05:48:54.905-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">14</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/chat-php-jquery.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 4</title><link>http://feedproxy.google.com/~r/CodingMix/~3/freimmD6J-o/creating-full-php-login-system-very_21.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 22 Nov 2010 05:15:20 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6678078753780952414</guid><description>Before reading this tutorial please read the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html" title="login register"&gt;previous parts&lt;/a&gt;. In this part of the tutorial we will discuss about how the users will log in and log out. I will use the same database as in the &lt;a href="http://www.codingmix.com/2010/11/creating-full-php-login-system-very.html"  title="login register"&gt;third part&lt;/a&gt; of the tutorial, if you have registered there now you can log in:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/login/" style="width:350px;height:295px;overflow:hidden;margin-left:100px;"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;To log in we will use sessions (here you can read more about &lt;a href="http://www.codingmix.com/2010/11/php-sessions.html" title="php sessions"&gt;sessions&lt;/a&gt;). As you already know, a session can transfer data from a page to another pages. When the user logs in we will create a session with the username and later we will check this session: while the session exists the user is logged in.&lt;br /&gt;&lt;br /&gt;But first we need the log in form:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&amp;lt;form action=&amp;quot;login.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Log in&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Log in&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;Don`t have an account?&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;And now we need to create the &lt;i&gt;login.php&lt;/i&gt; file. This file will create the session if the given username and password are matching. It will check the username and password by searching in the MySQL table for a row where the username field matches the given username and password field with the given password.&lt;br /&gt;&lt;i&gt;login.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start(); &lt;span style="color:green;"&gt;//Start sessions&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (&amp;quot;Could not connect to mysql because &amp;quot;.mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (&amp;quot;Could not select database because &amp;quot;.mysql_error());&lt;br /&gt;if(&lt;span style="color:red;"&gt;mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM users WHERE username='&amp;quot;.$_POST[&amp;quot;username&amp;quot;].&amp;quot;' and password='&amp;quot;.$_POST[&amp;quot;password&amp;quot;].&amp;quot;'&amp;quot;))==1&lt;/span&gt;){&lt;br /&gt;   session_register(&amp;quot;username&amp;quot;); &lt;span style="color:green;"&gt;//Create the session&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'Wrong username or password!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Now the session is created but we are not seeing the results. To see some results we will need to modify the &lt;i&gt;index.php&lt;/i&gt; to show a welcome message if the user is logged in, else to show the login and registration forms:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;:&lt;div class="code"&gt;&lt;span style="color:red;"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if(!session_is_registered(&amp;quot;username&amp;quot;)){?&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;login.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Log in&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Log in&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;Don`t have an account?&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;?php }&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:red;"&gt;echo 'Welcome ' . $_SESSION[&amp;quot;username&amp;quot;];&lt;/span&gt;&lt;br /&gt;}?&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;In this moment if you log in ,you need to go back to the &lt;i&gt;index.php&lt;/i&gt; file to see the welcome message. To solve this problem we will need to edit the &lt;i&gt;login.php&lt;/i&gt; file in a way to redirect the user back to &lt;i&gt;index.php&lt;/i&gt;. We will make this by using the &lt;i&gt;header("location:index.php")&lt;/i&gt; function:&lt;br /&gt;&lt;i&gt;login.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start(); &lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (&amp;quot;Could not connect to mysql because &amp;quot;.mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (&amp;quot;Could not select database because &amp;quot;.mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM users WHERE username='&amp;quot;.$_POST[&amp;quot;username&amp;quot;].&amp;quot;' and password='&amp;quot;.$_POST[&amp;quot;password&amp;quot;].&amp;quot;'&amp;quot;))==1){&lt;br /&gt;   session_register(&amp;quot;username&amp;quot;);&lt;br /&gt;   &lt;span style="color:red;"&gt;header(&amp;quot;location:index.php&amp;quot;);&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'Wrong username or password!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Now there is only one thing that needs to be done: the log out option. We will make logging out possible by creating a file: &lt;i&gt;logout.php&lt;/i&gt;. This file will simply delete the &lt;i&gt;username&lt;/i&gt; session and redirect the users back to &lt;i&gt;index.php&lt;/i&gt;, but first we need to include the log out button in the &lt;i&gt;index.php&lt;/i&gt; file:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if(!session_is_registered(&amp;quot;username&amp;quot;)){?&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;login.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Log in&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Log in&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;Don`t have an account?&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;?php }&lt;br /&gt;else{&lt;br /&gt;   echo 'Welcome ' . $_SESSION[&amp;quot;username&amp;quot;] . &lt;span style="color:red;"&gt;'&amp;lt;br/&amp;gt;&amp;lt;a href=&amp;quot;logout.php&amp;quot;&amp;gt;Log out&amp;lt;/a&amp;gt;'&lt;/span&gt;;&lt;br /&gt;}?&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;And here is the log out part:&lt;br /&gt;&lt;i&gt;logout.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;session_destroy(); &lt;span style="color:green;"&gt;//Delete session&lt;/span&gt;&lt;br /&gt;header(&amp;quot;location:index.php&amp;quot;);&lt;br /&gt;?&amp;gt;&lt;/div&gt;And now the script should work fine, if it doesn`t or you have a question please comment. This script can be easily adapted to any website, by checking the existence of the session on each page.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6678078753780952414?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Th1g_t2f1vHduBZMelvEo6PRg3A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Th1g_t2f1vHduBZMelvEo6PRg3A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Th1g_t2f1vHduBZMelvEo6PRg3A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Th1g_t2f1vHduBZMelvEo6PRg3A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/freimmD6J-o" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-22T05:15:20.857-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">36</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/creating-full-php-login-system-very_21.html</feedburner:origLink></item><item><title>PHP sessions</title><link>http://feedproxy.google.com/~r/CodingMix/~3/bKo4venSEWw/php-sessions.html</link><category>PHP</category><category>PHP lessons</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 05 Dec 2010 01:45:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-235628989561283244</guid><description>Sessions can transfer data between two or more pages. It`s somehow like a variable that keep`s it`s value even if you call it from an another file. Let`s say that we have a website and in the &lt;i&gt;index.php&lt;/i&gt; file we are asking for the name of the visitor and we store it in the &lt;i&gt;$name&lt;/i&gt; variable (e.g.:$name = 'Tom').&lt;div id="full-post"&gt; If the visitor navigates to an another page the value of &lt;i&gt;$name&lt;/i&gt; will be lost, so we would need to ask for the name on each page so in this case is way better to use sessions.&lt;br /&gt;&lt;br /&gt;In order to use a session first we need to "start" it:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;?&amp;gt;&lt;/div&gt; NOTE: The &lt;i&gt;session_start();&lt;/i&gt; function &lt;span style="color:red;"&gt;must be&lt;/span&gt; the at the very beginning of your code, even before the &lt;i&gt;&amp;lt;html&amp;gt;&lt;/i&gt; tag.&lt;br /&gt;&lt;br /&gt;A session variable look`s and works like an element of an associative array:&lt;div class="code"&gt;$_SESSION['name'] = 'Tom';&lt;br /&gt;echo $_SESSION['name'];&lt;/div&gt;&lt;br /&gt;And because sessions are keeping their value even if you go to an another page:&lt;br /&gt;&lt;i&gt;page1.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;$_SESSION['name'] = 'Tom';&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;page2.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;echo $_SESSION['name'] ;&lt;br /&gt;?&amp;gt;&lt;/div&gt;Will output&lt;div class="code"&gt;Tom&lt;/div&gt;&lt;br /&gt;Let`s say that we have a page that is displayed only to members. If somebody is logged in than it`s username is stored in a session. In order to show the content of the page to the visitor we need to check if the username session exists or not. This can be easily done using this function:&lt;div class="code"&gt;isset($_SESSION['username']); //Returns True if exists and False if not&lt;/div&gt;So if we use the &lt;i&gt;isset&lt;/i&gt; function our code will look like this:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;if(isset($_SESSION['username'])){&lt;br /&gt;   echo 'Welcome ' . $_SESSION['username'];&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   echo 'You are not logged in!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;When the user leaves your website or closes the browser the sessions are automatically deleted, but if you want to delete a session yourself use the following code: &lt;div class="code"&gt;unset($_SESSION['username']);&lt;/div&gt;This is useful when you want to delete only a single session.&lt;br /&gt;&lt;br /&gt;If you want to delete all the sessions use the following code:&lt;div class="code"&gt;session_destroy();&lt;/div&gt;NOTE: After this function you can`t use more sessions on the page.&lt;br /&gt;&lt;br /&gt;Example of using the &lt;i&gt;session_destroy();&lt;/i&gt; function:&lt;br /&gt;&lt;i&gt;log-out.php&lt;/i&gt;&lt;div class="code"&gt;session_start();&lt;br /&gt;session_destroy();&lt;/div&gt;By destroying the sessions the user is logged out.&lt;br /&gt;&lt;br /&gt;This is enough about sessions, but if you any question related to this session please ask!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-235628989561283244?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wdsmfmjiiknW9pzldNJUuvttxZo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wdsmfmjiiknW9pzldNJUuvttxZo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wdsmfmjiiknW9pzldNJUuvttxZo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wdsmfmjiiknW9pzldNJUuvttxZo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/bKo4venSEWw" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-05T01:45:00.558-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/php-sessions.html</feedburner:origLink></item><item><title>How to change title bar message using Javascript</title><link>http://feedproxy.google.com/~r/CodingMix/~3/FcYNq5UlyQw/change-title-bar-message-text.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 12 Nov 2010 06:31:14 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8072308504604825522</guid><description>For those who doesn`t know what is the title bar: The title bar is the top part of the browser window where the website`s (page) title is shown: &lt;img style="float:right; margin:0 50px 0 0;cursor:pointer; cursor:hand;width: 194px; height: 30px;" src="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TNwEz9GZFMI/AAAAAAAAAQw/13pgQILky58/s1600/title%2Bbar.png" border="0" alt="change title bar message"id="BLOGGER_PHOTO_ID_5538306932380079298" /&gt;In this lesson I will show you how the title bar message (text) can be changed using only Javascript.&lt;div id="full-post"&gt;&lt;br /&gt;The title bar message can be changed easily using the following property:&lt;div class="code"&gt;&lt;b&gt;document.title&lt;/b&gt;&lt;/div&gt;And the easiest way to use it is:&lt;div class="code"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;document.title = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;But there are many other, funny ways to change the title bar message:&lt;h2 style="background:none;color:#555;font-weight:bold;"&gt;Changing the title bar message&lt;/h2&gt;&lt;div class="code"&gt;&lt;center&gt;&lt;input type="text" id="newtitle" value="New title bar message..."/&gt;&lt;input type="button" value="Change title" onclick="changetitle(document.getElementById('newtitle').value);"/&gt;&lt;/center&gt;&lt;script type="text/javascript"&gt;function changetitle(to){document.title = to;}&lt;/script&gt;&lt;/div&gt;This is done by the following script:&lt;div class="code"&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle&amp;quot; value=&amp;quot;New title bar message...&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Change title&amp;quot; onclick=&amp;quot;changetitle(document.getElementById('newtitle').value);&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function changetitle(changeto){&lt;br /&gt;   document.title = changeto;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;h2 style="background:none;color:#555;font-weight:bold;"&gt;Dynamic title bar message&lt;/h2&gt;&lt;div class="code"&gt;&lt;center&gt;Title 1:&lt;input type="text" id="newtitle1" value="--"/&gt;&lt;br /&gt;Title 2:&lt;input type="text" id="newtitle2" value="----"/&gt;&lt;br /&gt;Title 3:&lt;input type="text" id="newtitle3" value="------"/&gt;&lt;br /&gt;Title 4:&lt;input type="text" id="newtitle4" value="--------"/&gt;&lt;br /&gt;Title 5:&lt;input type="text" id="newtitle5" value="----------"/&gt;&lt;br /&gt;&lt;input type="button" value="Start" onclick="clearTimeout(timeouttitle);starttitle();"/&gt;&lt;input type="button" value="Stop" onclick="clearTimeout(timeouttitle);"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Or loop from 0% to 100%&lt;/b&gt;&lt;br /&gt;&lt;input type="button" value="Start" onclick="clearTimeout(timeouttitleb);starttitleb();"/&gt;&lt;input type="button" value="Stop" onclick="clearTimeout(timeouttitleb);"/&gt;&lt;/center&gt;&lt;script type="text/javascript"&gt;var xaz=0;var timeouttitleb;var u=1;var timeouttitle;function starttitle(){document.title = document.getElementById('newtitle' + u).value;u++;if(u &gt; 5){u=1;}timeouttitle=setTimeout(starttitle,1000);}function starttitleb(){document.title = xaz + "%";xaz++;timeouttitleb=setTimeout(starttitleb,500);if(xaz&gt;100){clearTimeout(timeouttitleb);xaz=0;}}&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;Here is the script for the first example (loop through the 5 titles):&lt;div class="code"&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle1&amp;quot; value=&amp;quot;--&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 2:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle2&amp;quot; value=&amp;quot;----&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 3:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle3&amp;quot; value=&amp;quot;------&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 4:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle4&amp;quot; value=&amp;quot;--------&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Title 5:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;newtitle5&amp;quot; value=&amp;quot;----------&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Start&amp;quot; onclick=&amp;quot;clearTimeout(timeout);starttitle();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Stop&amp;quot; onclick=&amp;quot;clearTimeout(timeout);&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var i=1;&lt;br /&gt;var timeout;&lt;br /&gt;function starttitle(){&lt;br /&gt;   document.title = document.getElementById('newtitle' + i).value;&lt;br /&gt;   i++;&lt;br /&gt;   if(i &amp;gt; 5){&lt;br /&gt;      i=1; &lt;span style="color:green;"&gt;//When the 5th title is used go back to the first one&lt;/span&gt;&lt;br /&gt;   }&lt;br /&gt;   timeout = setTimeout(starttitle,1000); &lt;span style="color:green;"&gt;//1000 is the number of milliseconds between each change&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;br /&gt;And here is the script for the second example (loop from 1% to 100%):&lt;div class="code"&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Start&amp;quot; onclick=&amp;quot;clearTimeout(timeout);starttitle();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Stop&amp;quot; onclick=&amp;quot;clearTimeout(timeout);&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var number=0;&lt;br /&gt;var timeout;&lt;br /&gt;function starttitle(){&lt;br /&gt;   document.title = number + &amp;quot;%&amp;quot;;&lt;br /&gt;   number++;&lt;br /&gt;   timeout = setTimeout(starttitle,500);&lt;br /&gt;   if(number &amp;gt; 100){&lt;br /&gt;      clearTimeout(timeout); &lt;span style="color:green;"&gt;//When reach 100% stop and set &lt;i&gt;number&lt;/i&gt; back to 0&lt;/span&gt;&lt;br /&gt;      number = 0; &lt;span style="color:green;"&gt;//Without this line the script will be able to run only once&lt;/span&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;These where just some examples, but using this property you can change the title bar in almost any way. If you have any question or somethings is not working then let me know it in a comment!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8072308504604825522?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fRsQImnzzZCs3HxLmI9NWe8J63o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fRsQImnzzZCs3HxLmI9NWe8J63o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fRsQImnzzZCs3HxLmI9NWe8J63o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fRsQImnzzZCs3HxLmI9NWe8J63o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/FcYNq5UlyQw" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-12T06:31:14.648-08:00</app:edited><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TNwEz9GZFMI/AAAAAAAAAQw/13pgQILky58/s72-c/title%2Bbar.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/change-title-bar-message-text.html</feedburner:origLink></item><item><title>Cross-browser Chat script using PHP, MySQL and Javascript</title><link>http://feedproxy.google.com/~r/CodingMix/~3/CRUsjt1ild0/cross-browser-chat-script-using-php.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 31 Jan 2011 23:41:49 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-7073350657830778254</guid><description>I write this tutorial because the &lt;a href="http://www.codingmix.com/2010/09/simple-chat-script-in-php-mysql-and.html" title="chat script"&gt;first version&lt;/a&gt; of my Chat script had some problems in IE (Internet Explorer): After the message was submitted the page was not refreshed. Now I`we found the problem and a solution and here is the new, cross-browser chat script:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/chat3/chat.php" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;&lt;br /&gt;The chat is refreshed automatically each 30 seconds.&lt;br /&gt;&lt;br /&gt;This script works the same way as the &lt;a href="http://www.codingmix.com/2010/09/simple-chat-script-in-php-mysql-and.html" title="chat"&gt;old one&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Let`s start: First we need to create a MySQL table with 4 fields: &lt;div class="code"&gt;time - the time when the message was posted (UNIX)&lt;br /&gt;name - the name of the author of the message&lt;br /&gt;ip - the ip of the author of the message&lt;br /&gt;message - the message text&lt;/div&gt;To create the table (I will call it &lt;i&gt;chat&lt;/i&gt;) I`we used the following file:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Create the table&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;create table chat(&lt;br /&gt;   time int(11) NOT NULL, &lt;br /&gt;   name varchar(30) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   message varchar(255) NOT NULL, &lt;br /&gt;   PRIMARY KEY (time)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;For the rest of the Chat script we will need 3 more files:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Let`s start with the chat.php what will contain the forms and all the Ajax scripts what will trigger the other 2 files: &lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.message {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:498px;&lt;br /&gt;   margin-bottom:5px;&lt;br /&gt;   border:1px solid #999;&lt;br /&gt;}&lt;br /&gt;.messagehead {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#FFC;&lt;br /&gt;   width:500px;&lt;br /&gt;}&lt;br /&gt;.messagecontent {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:496px;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;width:500px;margin:0 auto;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain the messages&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain an eventual error message&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;error&amp;quot; style=&amp;quot;width:500px;text-align:center;color:red;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div contains the forms and the send button&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;write&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&amp;gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;Name:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; onClick=&amp;quot;send();&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will display the messages&lt;/span&gt;&lt;br /&gt;function showmessages(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'show-message.php' file&lt;/span&gt;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      &lt;span style="color:red;"&gt;//And here is the line what makes it cross-browser:&lt;/span&gt;&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;show-messages.php&lt;span style="color:red;"&gt;?&amp;quot; + Math.random()&lt;/span&gt;,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;showmessages.php&lt;span style="color:red;"&gt;?&amp;quot; + Math.random()&lt;/span&gt;,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Replace the content of the &lt;i&gt;messages&lt;/i&gt; with the response from the 'show-messages.php' file&lt;/span&gt;&lt;br /&gt;   document.getElementById('messages').innerHTML = xmlhttp.responseText;&lt;br /&gt;   &lt;span style="color:green;"&gt;//Repeat the function each 30 seconds&lt;/span&gt;&lt;br /&gt;   setTimeout('showmessages()',30000);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Start the &lt;i&gt;showmessages()&lt;/i&gt; function&lt;/span&gt;&lt;br /&gt;showmessages();&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will submit the message&lt;/span&gt;&lt;br /&gt;function send(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'send.php' file with all the required informations&lt;/span&gt;&lt;br /&gt;   var sendto = 'send.php?message=' + document.getElementById('message').value + '&amp;amp;name=' + document.getElementById('name').value;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   var error = '';&lt;br /&gt;   &lt;span style="color:green;"&gt;//If an error occurs the 'send.php' file send`s the number of the error and based on that number a message is displayed&lt;/span&gt;&lt;br /&gt;   switch(parseInt(xmlhttp.responseText)){&lt;br /&gt;   case 1:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      error = 'Don`t forget the message!';&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      error = 'The message is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 5:&lt;br /&gt;      error = 'Don`t forget the name!';&lt;br /&gt;      break;&lt;br /&gt;   case 6:&lt;br /&gt;      error = 'The name is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 7:&lt;br /&gt;      error = 'This name is already used by somebody else!';&lt;br /&gt;      break;&lt;br /&gt;   case 8:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;   }&lt;br /&gt;   if(error == ''){&lt;br /&gt;      document.getElementById('error').innerHTML = '';&lt;br /&gt;      showmessages();&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      document.getElementById('error').innerHTML = error;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (1);&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is empty and send the error code&lt;/span&gt;&lt;br /&gt;if(strlen($message) &amp;lt; 1){&lt;br /&gt;   echo 3;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($message) &amp;gt; 255){&lt;br /&gt;   echo 4;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is empty&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;lt; 1){&lt;br /&gt;   echo 5;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;gt; 29){&lt;br /&gt;   echo 6;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if the name is used by somebody else&lt;/span&gt;&lt;br /&gt;else if(mysql_num_rows(mysql_query(&amp;quot;select * from chat where name = '&amp;quot; . $name . &amp;quot;' and ip != '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 7;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//If everything is fine&lt;/span&gt;&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//This array contains the characters what will be removed from the message and name, because else somebody could send redirection script or links&lt;/span&gt;&lt;br /&gt;   $search = array(&amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;,&amp;quot;&amp;amp;lt;&amp;quot;);&lt;br /&gt;   &lt;span style="color:green;"&gt;//Insert a new row in the chat table&lt;/span&gt;&lt;br /&gt;   mysql_query(&amp;quot;insert into chat values ('&amp;quot; . time() . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$name) . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$message) . &amp;quot;')&amp;quot;) or die(8);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die(2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Get the first 10 messages ordered by time&lt;/span&gt;&lt;br /&gt;$result = mysql_query(&amp;quot;select * from chat order by time desc limit 0,10&amp;quot;);&lt;br /&gt;$messages = array();&lt;br /&gt;&lt;span style="color:green;"&gt;//Loop and get in an array all the rows until there are not more to get&lt;/span&gt;&lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Put the messages in divs and then in an array&lt;/span&gt;&lt;br /&gt;   $messages[] = &amp;quot;&amp;lt;div class='message'&amp;gt;&amp;lt;div class='messagehead'&amp;gt;&amp;quot; . $row[name] . &amp;quot; - &amp;quot; . date('g:i A M, d Y',$row[time]) . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='messagecontent'&amp;gt;&amp;quot; . $row[message] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;   &lt;span style="color:green;"&gt;//The last posts date&lt;/span&gt;&lt;br /&gt;   $old = $row[time];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Display the messages in an ascending order, so the newest message will be at the bottom&lt;/span&gt;&lt;br /&gt;for($i=9;$i&amp;gt;=0;$i--){&lt;br /&gt;   echo $messages[$i];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//This is the more important line, this deletes each message older then the 10th message ordered by time is deleted, so the table will never have to store more than 10 messages.&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;delete from chat where time &amp;lt; &amp;quot; . $old);&lt;br /&gt;?&amp;gt;&lt;/div&gt;If we try to send multiple times the httpRequest to the same file IE will cache the first response and it will return the first result each time. To make IE to believe that we are sending the request to an another file we will use the url in the following way: &lt;div class="code"&gt;'file.php?' + Math.random&lt;br /&gt;this will result something like this: &lt;i&gt;file.php?0.12321321&lt;/i&gt; - this is a new file for IE&lt;/div&gt;Try it out and don`t hesitate to ask if something is not clear or if you find an error!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-7073350657830778254?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/azZd93qw0Qw5SAroFjtBvrOqeoU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/azZd93qw0Qw5SAroFjtBvrOqeoU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/azZd93qw0Qw5SAroFjtBvrOqeoU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/azZd93qw0Qw5SAroFjtBvrOqeoU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/CRUsjt1ild0" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-31T23:41:49.151-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">107</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/cross-browser-chat-script-using-php.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 3</title><link>http://feedproxy.google.com/~r/CodingMix/~3/Yaz29NCvDOg/creating-full-php-login-system-very.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 21 Nov 2010 10:50:25 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-3093255739594364336</guid><description>This is the third part of this tutorial (here is the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html" title="PHP Login system"&gt;first&lt;/a&gt;). In this part we will complete the registration process by recording the registration details in our MySQL table: &lt;i&gt;users&lt;/i&gt; and by outputting different error messages for different errors that may occur (e.g.: username already exist, password too short... ). &lt;div id="full-post"&gt;&lt;br /&gt;In the previous part of this tutorial we have discussed about how we can get the value of a text input. Now we will need to store these values in our MySQL table. To insert the data into the table we will use the &lt;i&gt;insert&lt;/i&gt; query: &lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;?&amp;gt;&lt;/div&gt;When using this query make sure you put the data in the right order (name,password)!&lt;br /&gt;&lt;br /&gt;The above code will not write out any success message, it will just simply insert the data into the &lt;i&gt;users&lt;/i&gt; table. To see the result you should &lt;a href="http://www.codingmix.com/2010/10/display-data-from-mysql-table-using-php.html" target="_blank"&gt;display the data from the mysql table&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now try to register twice with the same username. Because the username need`s to be unique you will get an error like this: &lt;div class="code"&gt;Duplicate entry 'username' for key 'PRIMARY'&lt;/div&gt;To avoid such errors we should begin with checking the username. We will check it using the &lt;i&gt;select&lt;/i&gt; query and the &lt;i&gt;mysql_num_rows&lt;/i&gt; function. &lt;br /&gt;&lt;br /&gt;This is very simple. We will count the rows where the username is the one what we are searching for. If this number is 0 means that the username is not in the table so we can register it, if it`s 1 than there is already somebody with this username in our table. &lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * from users WHERE username='&amp;quot; . $_POST['username'] . &amp;quot;'&amp;quot;)) == 1){&lt;br /&gt;   echo &amp;quot;Sorry, this username is already taken!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;In the same way (using if/else and else if statements) we will need to check for a list of possible errors: &lt;div class="code"&gt;Username too long&lt;br /&gt;Username too short&lt;br /&gt;Password too long&lt;br /&gt;Password too short&lt;br /&gt;Invalid characters in password&lt;br /&gt;Invalid characters in username&lt;br /&gt;&lt;/div&gt;This is a very simple, here is my code:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * from users WHERE username='&amp;quot; . $_POST['username'] . &amp;quot;'&amp;quot;)) == 1){&lt;br /&gt;   echo &amp;quot;Sorry, this username is already taken!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['username']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Username is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['username']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Username is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Password is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Password is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['username'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in username!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['password'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in password!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;These days most of the registration forms have a &lt;i&gt;retype password&lt;/i&gt; field, to avoid mistyped passwords. To add this feature to our registration form we will need to edit both the &lt;i&gt;index.php&lt;/i&gt; and the &lt;i&gt;register.php&lt;/i&gt; files. First we need to include the retype password text input and secondly to compare the two passwords.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;i&gt;register.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * from users WHERE username='&amp;quot; . $_POST['username'] . &amp;quot;'&amp;quot;)) == 1){&lt;br /&gt;   echo &amp;quot;Sorry, this username is already taken!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;else if($_POST['password'] != $_POST['retype-password']){&lt;br /&gt;   echo &amp;quot;The two passwords don`t match!&amp;quot;;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;else if(strlen($_POST['username']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Username is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['username']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Username is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Password is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Password is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['username'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in username!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['password'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in password!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Here is a live demo of what we have until now:&lt;iframe src="http://coolboycsaba.freehostia.com/login-example2/" style="width:350px;height:180px;overflow:hidden;margin-left:100px;"&gt;&lt;/iframe&gt;&lt;br /&gt;And here is a list with the registered users (it`s &lt;b&gt;not&lt;/b&gt; refreshing when you register!)&lt;iframe src="http://coolboycsaba.freehostia.com/login/registered-users.php" style="border:1px solid #999;width:520px;height:100px;margin-left:5px;float:left;"&gt;&lt;/iframe&gt;&lt;br /&gt;And this is enough for now. If something doesn`t work or you have a question just ask in a comment and I will try to answer to each comment.&lt;br /&gt;&lt;br /&gt;Here you can find the &lt;a href="http://www.codingmix.com/2010/11/creating-full-php-login-system-very_21.html" title="login register"&gt;4th part of the tutorial&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-3093255739594364336?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qs-crH1-VbgJeW83yIYfMeUgLwY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qs-crH1-VbgJeW83yIYfMeUgLwY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qs-crH1-VbgJeW83yIYfMeUgLwY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qs-crH1-VbgJeW83yIYfMeUgLwY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/Yaz29NCvDOg" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-21T10:50:25.470-08:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/creating-full-php-login-system-very.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 2</title><link>http://feedproxy.google.com/~r/CodingMix/~3/V39BVgrx0ss/creating-full-php-login-system-very_29.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 03 Nov 2010 07:27:29 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5168213691621313436</guid><description>This is the second part of this tutorial. In the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html"&gt;first part&lt;/a&gt; we created a MySQL table to store the required user informations. In this part we will continue our Login/Register system by making registration possible.&lt;div id="full-post"&gt;&lt;br /&gt;First we will need to create an empty &lt;i&gt;.php&lt;/i&gt; page, later this page will contain the log in and the register form. I will name it &lt;i&gt;index.php&lt;/i&gt; because when you enter the URL of a website or a folder in the address bar the browser will open the first file with the name &lt;i&gt;index&lt;/i&gt;. For sure you can name it anyway you want if you want to make registration and logging in possible only from a secondary page.&lt;br /&gt;Here is my &lt;i&gt;index.php&lt;/i&gt; file:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Now we need to create the registration form, this will contain a text inputs for the username, a password input for the password and a submit button. This form will be placed in the &lt;i&gt;index.php&lt;/i&gt; page.&lt;br /&gt;Here is an example of how it should look: &lt;div class="code"&gt;&lt;form&gt;&lt;br /&gt;&lt;b style="font-size:150%;"&gt;Register&lt;/b&gt;&lt;br /&gt;Username: &lt;input type="text" name="username"/&gt;&lt;br /&gt;Password: &lt;input type="password" name="password"/&gt;&lt;br /&gt;&lt;input type="button" value="Register" /&gt;&lt;br /&gt;&lt;/form&gt; &lt;/div&gt;&lt;small&gt;(The form is just an example, it will do nothing if you press the Register button.)&lt;/small&gt; &lt;br /&gt;&lt;br /&gt;Later we will create a file called &lt;i&gt;register.php&lt;/i&gt;. The above form will be submitted to this new file and this file (&lt;i&gt;register.php&lt;/i&gt;) will read the value of the username and the password input, but to make reading it possible we will need to set the name attribute of the two field: the username input will be called &lt;i&gt;username&lt;/i&gt; and the password input &lt;i&gt;password&lt;/i&gt;. After this we just need to specify the page to submit the form to and the submission method. As I said before the form will be submitted to &lt;i&gt;register.php&lt;/i&gt; using &lt;i&gt;post&lt;/i&gt; as method.&lt;br /&gt;After making the above modifications my &lt;i&gt;index.php&lt;/i&gt; file look`s in the following way:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;Now let`s start to write the &lt;i&gt;register.php&lt;/i&gt; file. First we will make it to write out the username and the password to familiarize with PHP and how to read from a form. At this step my &lt;i&gt;register.php&lt;/i&gt; look`s in the following way:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;echo $_POST[&amp;quot;username&amp;quot;] . &amp;quot;&amp;lt;br /&amp;gt;&amp;quot; . $_POST[&amp;quot;password&amp;quot;];&lt;br /&gt;?&amp;gt;&lt;/div&gt;The &lt;b&gt;$_POST[&lt;span style="color:red;"&gt;"username"&lt;/span&gt;]&lt;/b&gt; function reads the value of the input with the name specified in the parameter (in red), in our case &lt;i&gt;"username"&lt;/i&gt;. (This function works only with method="post" forms.) &lt;br /&gt;&lt;br /&gt;Here is a live demo of what we have until now: &lt;iframe src="http://coolboycsaba.freehostia.com/login-example1/" style="width:300px;height:150px;overflow:hidden;margin-left:125px;"&gt;&lt;/iframe&gt;&lt;br /&gt;This is enough for now. If you have a question or something it`s not working just ASK ME!&lt;br /&gt;&lt;br /&gt;Here is the &lt;a href="http://www.codingmix.com/2010/11/creating-full-php-login-system-very.html"&gt;third part&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5168213691621313436?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NuoV7VrRrox4FfJrM4PBJDTixIw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NuoV7VrRrox4FfJrM4PBJDTixIw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NuoV7VrRrox4FfJrM4PBJDTixIw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NuoV7VrRrox4FfJrM4PBJDTixIw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/V39BVgrx0ss" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-03T07:27:29.831-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/creating-full-php-login-system-very_29.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 1</title><link>http://feedproxy.google.com/~r/CodingMix/~3/AhUb_sH-2og/creating-full-php-login-system-very.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 29 Oct 2010 05:45:15 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5112372583892540438</guid><description>In this tutorial we will make a full PHP Login script, what will allow users to register, login and to log out. This system can be easily used on any PHP website. In this tutorial we will deal more with the technical (PHP) part and less with styling it, as you can see it in the bellow example of how the login system will look and work:&lt;div id="full-post"&gt;&lt;iframe src='http://coolboycsaba.freehostia.com/login/' style="width:530px;height:300px;"&gt;&lt;/iframe&gt;&lt;br /&gt;When somebody registers the username and the password is stored in a MySQL table. When somebody tries to log in the script will verify if exists an user with the given username and password in the MySQL table. If the login was successful a session is created and a welcome message is displayed. From here the user can log out by destroying the session.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Creating the &lt;i&gt;users&lt;/i&gt; MySQL table&lt;/b&gt;&lt;br /&gt;As I said, the username and the password of each user will be stored in a MySQL table. I will call this table &lt;i&gt;users&lt;/i&gt;. We need two columns: &lt;i&gt;username&lt;/i&gt; and &lt;i&gt;password&lt;/i&gt;. &lt;br /&gt;I`we used the following file to create the table:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style='color:green;'&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;&lt;span style='color:green;'&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;&lt;span style='color:green;'&gt;//Create the table&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;create table users(&lt;br /&gt;   username varchar(30) NOT NULL, &lt;br /&gt;   password varchar(30) NOT NULL, &lt;br /&gt;   PRIMARY KEY (username)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;&lt;span style='color:green;'&gt;//Show "Complete" if everything works&lt;/span&gt;&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;Now let`s take apart this code and talk about the following code:&lt;div class="code"&gt;mysql_query(&amp;quot;create table users(&lt;br /&gt;   username varchar(30) NOT NULL, &lt;br /&gt;   password varchar(30) NOT NULL, &lt;br /&gt;   PRIMARY KEY (username)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;/div&gt;By using &lt;i&gt;mysql_query&lt;/i&gt; we "ask" the MySQL database to do something. In this case we ask it to create a table with the name &lt;i&gt;users&lt;/i&gt;: &lt;b&gt;create table users&lt;/b&gt;.&lt;br /&gt;After this we need to specify some details about the table. These details needs to be placed between brackets ("()"). &lt;br /&gt;First we will specify the two fields (columns): &lt;div class="code"&gt;username varchar(30) NOT NULL,&lt;br /&gt;password varchar(30) NOT NULL&lt;/div&gt;"username" and "password" is the name of the field.&lt;br /&gt;"varchar" is the data type of the field - it will contain characters&lt;br /&gt;"(30)" is the maximum length of the field&lt;br /&gt;"NOT NULL" means the field can`t be leaved blank&lt;br /&gt;And we specify the PRIMARY KEY:&lt;br /&gt;&lt;div class="code"&gt;PRIMARY KEY (username)&lt;/div&gt;The primary key is an unique identifier, this means that there can`t be two users with the same username.&lt;br /&gt;&lt;br /&gt;Now just run your &lt;i&gt;create-table.php&lt;/i&gt; but don`t forget to change the host, database and the password to yours. If everything works you will see the message: "Complete.", otherwise an error message. In this case double check your code or ASK ME!&lt;br /&gt;&lt;br /&gt;Here is the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very_29.html" title="php login system"&gt;second part!&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5112372583892540438?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WXpb_O6PYSHvgjQm1qxFLi1z11Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WXpb_O6PYSHvgjQm1qxFLi1z11Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WXpb_O6PYSHvgjQm1qxFLi1z11Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WXpb_O6PYSHvgjQm1qxFLi1z11Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/AhUb_sH-2og" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-29T05:45:15.801-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html</feedburner:origLink></item><item><title>Display data from MySQL table using PHP</title><link>http://feedproxy.google.com/~r/CodingMix/~3/a9EjqU005Rc/display-data-from-mysql-table-using-php.html</link><category>PHP</category><category>PHP lessons</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 15 Oct 2010 09:03:16 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6606276523826608835</guid><description>In this lesson I will teach you how to display data from a MySQL table using PHP. In order to be able to display data from a MySQL table, first we will need a MySQL table to display data from.&lt;br /&gt; &lt;br /&gt;&lt;div id="full-post"&gt;For this tutorial I will use the &lt;i&gt;example&lt;/i&gt; MySQL table:&lt;table border="1" align="center"&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Age&lt;/th&gt;&lt;th&gt;Country&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Joe&lt;/td&gt;&lt;td&gt;45&lt;/td&gt;&lt;td&gt;India&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Emily&lt;/td&gt;&lt;td&gt;19&lt;/td&gt;&lt;td&gt;USA&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Emma&lt;/td&gt;&lt;td&gt;23&lt;/td&gt;&lt;td&gt;Romania&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;34&lt;/td&gt;&lt;td&gt;Hungary&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;To read out the data from the table we will nned to use two functions:&lt;br /&gt;&lt;i&gt;mysql_query&lt;/i&gt; and &lt;i&gt;mysql_fetch_array&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;h2 style="background:none;color:#555;font-weight:bold;"&gt;mysql_query&lt;/h2&gt;&lt;/b&gt;The &lt;i&gt;mysql_query&lt;/i&gt; function requests information from the database. This function returns &lt;i&gt;false&lt;/i&gt; on error, else it returns a &lt;i&gt;resource&lt;/i&gt;. A resource is special data type, it holds a reference to an external resource. Additional functions are required to extract data from it.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;h2 style="background:none;color:#555;font-weight:bold;"&gt;mysql_fetch_array&lt;/h2&gt;&lt;/b&gt;The &lt;i&gt;mysql_fetch_array&lt;/i&gt; function returns an the first row of data from the resource returned from the &lt;i&gt;mysql_query&lt;/i&gt; function and moves the internal data pointer ahead to the beginning of the following row. The internal data pointer shows the place from where you are reading. If you run this function two times, first it will return an array of the data from the first row of the table, secondly it will return an array of the data from the &lt;b&gt;second&lt;/b&gt; row, because the function moves the internal data pointer to the beginning of the following row. If there are no more rows than it returns &lt;i&gt;false&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Now let`s put all together&lt;/b&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;//Use the &lt;i&gt;mysql_query&lt;/i&gt; function to extract everything from the &lt;i&gt;example&lt;/i&gt; table&lt;br /&gt;$result = mysql_query(&amp;quot;SELECT * from example&amp;quot;);&lt;br /&gt;&lt;span style="color:green;"&gt;//Use the &lt;i&gt;mysql_fetch_array&lt;/i&gt; function on the resource returned by the &lt;i&gt;mysql_query&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;$row = mysql_fetch_array($result);&lt;br /&gt;&lt;span style="color:green;"&gt;//Display the results&lt;/span&gt;&lt;br /&gt;echo $row['name'] . " - " . $row['age'] . " - " . $row['country'];&lt;br /&gt;?&amp;gt;&lt;/div&gt;The above code will display: &lt;div class="code"&gt;Joe - 45 - India&lt;/div&gt;Only the first line is displayed because we used only one the &lt;i&gt;mysql_fetch_array&lt;/i&gt; function. To display the data from each row we could write the last part of the code multiple times, once for each row or we could simply use a loop. Because &lt;i&gt;mysql_fetch_array&lt;/i&gt; returns null when there are no more rows to fetch we can use it as the condition of a while loop in the following way:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;$result = mysql_query(&amp;quot;SELECT * from example&amp;quot;);&lt;br /&gt;&lt;span style="color:green;"&gt;//While there are rows to display&lt;/span&gt;&lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Display the results from the current row and a line break&lt;/span&gt;&lt;br /&gt;   echo $row['name'] . " - " . $row['age'] . " - " . $row[country] . "&amp;lt;br /&amp;gt;";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;And this will display:&lt;div class="code"&gt;Joe - 45 - India&lt;br /&gt;Emily - 19 - USA&lt;br /&gt;Emma - 23 - Romania&lt;br /&gt;Bob - 34 - Hungary&lt;/div&gt;Now we just need to put the displayed result in a HTML table. I assume that everyone of you knows how a HTML table looks like.&lt;br /&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;$result = mysql_query(&amp;quot;SELECT * from example&amp;quot;);&lt;br /&gt;&lt;span style="color:green;"&gt;//Table starting tag and header cells&lt;/span&gt;&lt;br /&gt;echo &amp;quot;&amp;lt;table border='1'&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Age&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;;&lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Display the results in different cells&lt;/span&gt;&lt;br /&gt;   echo &amp;quot;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;quot; . $row['name'] . &amp;quot;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;quot; . $row['age'] . &amp;quot;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;quot; . $row['country'] . &amp;quot;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Table closing tag&lt;/span&gt;&lt;br /&gt;echo &amp;quot;&amp;lt;/table&amp;gt;&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;And now a nice table full of data will be displayed. These functions and methods can be used in many ways with minor modifications.&lt;br /&gt;&lt;br /&gt;Thanks for reading my blog! If you have any question or problem don`t hesitate, ASK ME!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6606276523826608835?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5jVnXyz0Ur9nNOlRynQ3fWuQsvw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5jVnXyz0Ur9nNOlRynQ3fWuQsvw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5jVnXyz0Ur9nNOlRynQ3fWuQsvw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5jVnXyz0Ur9nNOlRynQ3fWuQsvw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/a9EjqU005Rc" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-15T09:03:16.542-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/display-data-from-mysql-table-using-php.html</feedburner:origLink></item><item><title>Wow, My FIRST Yahoo Widget got 1000+ downloads</title><link>http://feedproxy.google.com/~r/CodingMix/~3/ulpiWrDxj4U/wow-my-first-yahoo-widget-got-1000.html</link><category>Miscellaneous</category><category>Miscellaneous yahoo widgets</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 25 Oct 2010 06:59:44 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-2915272425457743329</guid><description>Nearly 2 months ago I`we downloaded the Yahoo! Widgets application and I wondered how the widgets are made. After googling it I`we found that the widgets are written in Javascript and XML, and I`we decided to create a widgets. &lt;div id="full-post"&gt;&lt;br /&gt;It took me some time to think out a good widget idea, something simple but useful what people may want to download and use, something what looks good without using a very complicated images (because I`m not a Photoshop expert). I got more ideas but finally I`we decided to create a simple Calculator (mathematical) widget. &lt;br /&gt;&lt;br /&gt;Writing the code of the widget wasn`t big deal. It took me around 2-3 hours if I remember right. After writing it I`we submitted it to Yahoo! Widgets and it was published on august 25. Since than it was downloaded more than 1000 times. Bellow is an image of the widget and a link to it (on yahoo widgets):&lt;img style="display:block; margin:0px auto 10px; text-align:center;width: 158px; height: 183px;" src="http://l.yimg.com/hu/userimages/8348_1_7_04Screenshot.png" border="0" alt="" /&gt;And the widget is here: &lt;a href="http://widgets.yahoo.com/widgets/calculator-3" target="_blank"&gt;Calculator&lt;/a&gt;&lt;br /&gt;Please review it and say what do you think about it.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-2915272425457743329?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pPNuLA0WypcEGlGoTnEmUt53g0g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pPNuLA0WypcEGlGoTnEmUt53g0g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pPNuLA0WypcEGlGoTnEmUt53g0g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pPNuLA0WypcEGlGoTnEmUt53g0g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/ulpiWrDxj4U" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-25T06:59:44.600-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/wow-my-first-yahoo-widget-got-1000.html</feedburner:origLink></item><item><title>How to create a POLL system using PHP, MySQL and Ajax</title><link>http://feedproxy.google.com/~r/CodingMix/~3/HFCXpo3ocOA/how-to-create-poll-system-using-php.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Thu, 07 Oct 2010 06:19:34 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6019809021433487074</guid><description>In this tutorial I will show you how to create a basic POLL system using PHP, MySQL and Ajax. This poll will have some great features like: nobody can vote multiple times and the result of the poll is shown automatically after voting without refreshing the page.&lt;div id="full-post"&gt; Here is a live demo:&lt;div class="code"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/poll/poll.php" style="width:330px;height:150px;border:none;margin:0 0 0 150px;"&gt;&lt;/iframe&gt;&lt;/div&gt;The poll system uses a MySQL table to store the votes. This table requires only two columns: &lt;div class="code"&gt;vote - the number of the selected option (the "Yes..." option has the number 2)&lt;br /&gt;ip - the ip is used to prevent multiple votes&lt;/div&gt;To create the table you can use the following file:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&lt;?php &lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_query("create table poll(&lt;br /&gt;   vote tinyint(2) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   PRIMARY KEY (ip)&lt;br /&gt;)") or die (mysql_error());&lt;br /&gt;echo "Complete.";&lt;br /&gt;?&gt;&lt;/div&gt;The poll itself is made from two files. One contains the forms and the javascript and ajax parts, and an another file what`s called by the first one. &lt;br /&gt;The first file (poll.php) just sends the selected option number to the second file (vote.php) and displays the response. Here is my poll.php:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;poll.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.votes {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#CCC;&lt;br /&gt;   height:20px;&lt;br /&gt;   width:100px;&lt;br /&gt;   margin:5px 0 0 23px;&lt;br /&gt;   float:left;&lt;br /&gt;}&lt;br /&gt;.percentage {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#F00;&lt;br /&gt;   height:20px;&lt;br /&gt;}&lt;br /&gt;.option {&lt;br /&gt;   position:absolute;&lt;br /&gt;   width:100px;&lt;br /&gt;   height:20px;&lt;br /&gt;}&lt;br /&gt;.percentagetext {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:75px;&lt;br /&gt;   height:20px;&lt;br /&gt;   margin:5px 0 0 0;&lt;br /&gt;   float:left;&lt;br /&gt;   text-align:left;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;poll&amp;quot; style=&amp;quot;width:200px;overflow:hidden;text-align:center;&amp;quot;&amp;gt;&lt;br /&gt;Do you like this poll?&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div style=&amp;quot;text-align:left;width:180px;margin:0 auto;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll1&amp;quot; checked&amp;gt;Yes, it`s great&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll2&amp;quot;&amp;gt;Yes...&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll3&amp;quot;&amp;gt;Not bad...&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll4&amp;quot;&amp;gt;No!&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Vote!&amp;quot; onClick=&amp;quot;vote();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function vote(){&lt;br /&gt;   for(var i=1;i&amp;lt;=4;i++){&lt;br /&gt;      if(document.getElementById('poll' + i).checked){&lt;br /&gt;         &lt;span style="color:green;"&gt;//Check which one has been checked&lt;/span&gt;&lt;br /&gt;         var sendto = 'vote.php?vote=' + i;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;// Call the vote.php file&lt;/span&gt;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest;&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Output the response&lt;/span&gt;&lt;br /&gt;   document.getElementById('poll').innerHTML = xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;The CSS code is used to bring style to the response.&lt;br /&gt;&lt;br /&gt;Now let`s create the &lt;i&gt;vote.php&lt;/i&gt; file. This file will need to check if the user has already voted or not (by checking the ip) and it will need to calculate the percentage of votes and output the result in HTML format:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;vote.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('borcsa9_database');&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if the current user has already voted or not&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//&lt;i&gt;@$REMOTE_ADDR&lt;/i&gt; is used to get the ip of the user&lt;/span&gt;&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;select * from poll where ip = '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 'You can vote only once!';&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//If the user had not voted then insert the new vote in the &lt;i&gt;poll&lt;/i&gt; table&lt;/span&gt;&lt;br /&gt;   mysql_query(&amp;quot;insert into poll values ('&amp;quot; . $vote . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;')&amp;quot;) or die (mysql_error());&lt;br /&gt;}&lt;br /&gt;$mostvotes = 0;&lt;br /&gt;for($i=1;$i&amp;lt;=4;$i++){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Create an array of votes for each option&lt;/span&gt;&lt;br /&gt;   $votes[$i] = mysql_num_rows(mysql_query(&amp;quot;select * from poll where vote = &amp;quot; . $i));&lt;br /&gt;   if($votes[$i] &amp;gt; $mostvotes){&lt;br /&gt;      &lt;span style="color:green;"&gt;//Select the option with the higher number of votes&lt;/span&gt;&lt;br /&gt;      $mostvotes = $votes[$i];&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Each vote&lt;/span&gt;&lt;br /&gt;   $allvotes += $votes[$i];&lt;br /&gt;}&lt;br /&gt;$option[1] = 'Yes, it`s great';&lt;br /&gt;$option[2] = 'Yes...';&lt;br /&gt;$option[3] = 'Not bad...';&lt;br /&gt;$option[4] = 'No!';&lt;br /&gt;&lt;span style="color:green;"&gt;//Generate the result in a HTML form by calculating the percentage of each option and showing the number of votes&lt;/span&gt;&lt;br /&gt;for($i=1;$i&amp;lt;=4;$i++){&lt;br /&gt;   echo &amp;quot;&amp;lt;div class='votes'&amp;gt;&amp;lt;div class='option'&amp;gt;&amp;quot; . $option[$i] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='percentage' style='width:&amp;quot; . floor($votes[$i] / $allvotes * 100) . &amp;quot;px'&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class='percentagetext'&amp;gt; - &amp;quot; . floor($votes[$i] / $allvotes * 100) . &amp;quot;% (&amp;quot; . $votes[$i] . &amp;quot;)&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;And the our poll system is ready to use. This is a very basic poll system, but this can be easily modified by adding more style or more functions to it.&lt;br /&gt;If you have any question, don`t hesitate, ask!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6019809021433487074?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SiML18TSSShjfM-IH-6ua89dP4o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SiML18TSSShjfM-IH-6ua89dP4o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SiML18TSSShjfM-IH-6ua89dP4o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SiML18TSSShjfM-IH-6ua89dP4o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/HFCXpo3ocOA" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-07T06:19:34.457-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">17</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/how-to-create-poll-system-using-php.html</feedburner:origLink></item><item><title>A very simple C++ Tic Tac Toe game (v2)</title><link>http://feedproxy.google.com/~r/CodingMix/~3/19jp-lgHtyc/very-simple-cplusplus-tic-tac-toe-game.html</link><category>Cplusplus projects</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 01 Oct 2010 13:45:13 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-1501933207832143526</guid><description>This is my second C++ Tic Tac Toe game. This one has a shorter source-code because instead of using a variable for each square I`we used a two-dimensional array. With arrays is more simple to check if a square is available or to check for an eventual winner. &lt;div id="full-post"&gt;The rest of the game is almost the same as the &lt;a href="http://www.codingmix.com/2010/07/simples-cplusplus-tic-tac-toe-game-ever_24.html"&gt;first version&lt;/a&gt;, the only difference is that I`we used &lt;i&gt;char&lt;/i&gt;s instead of &lt;i&gt;int&lt;/i&gt;s to show the state of the squares.&lt;br /&gt;&lt;br /&gt;Required knowledge: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-4-variables.html"&gt;variables&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-5-inputoutput.html"&gt;input/output&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-6-ifelseelse-if_18.html"&gt;if/else/else if statements&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/07/cplusplus-lesson-8-while-loop-and-for.html"&gt;loop&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/09/cplusplus-lesson-9-arrays.html"&gt;arrays&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here is my code:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//This array of &lt;i&gt;char&lt;/i&gt;s represents the game board, and it holds the content of each square (x,o or empty)&lt;/span&gt;&lt;br /&gt;   char square[3][3] = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}};&lt;br /&gt;   &lt;span style="color:green;"&gt;//The current player (x or o)&lt;/span&gt;&lt;br /&gt;   char turn = 'X';&lt;br /&gt;   &lt;span style="color:green;"&gt;//These variables will hold the number of the row and column selected by the players.&lt;/span&gt;&lt;br /&gt;   int row;&lt;br /&gt;   int column;&lt;br /&gt;   &lt;span style="color:green;"&gt;//The winner (x, o, t(if it`s a tie) or empty)&lt;/span&gt;&lt;br /&gt;   char winner = ' ';&lt;br /&gt;   &lt;span style="color:green;"&gt;//Required variables to check if a move is valid or not&lt;/span&gt;&lt;br /&gt;   bool validmove;&lt;br /&gt;   bool validrow;&lt;br /&gt;   bool validcolumn;&lt;br /&gt;   &lt;span style="color:green;"&gt;//The game loop`s again and again until the game is over&lt;/span&gt;&lt;br /&gt;   while(winner == ' '){&lt;br /&gt;      &lt;span style="color:green;"&gt;//Draw the board&lt;/span&gt;&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot; 1 2 3&amp;quot; &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot; +---+---+---+&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      for(int i=1;i&amp;lt;4;i++){&lt;br /&gt;         cout &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; | &amp;quot; &amp;lt;&amp;lt; square[i-1][0] &amp;lt;&amp;lt; &amp;quot; | &amp;quot; &amp;lt;&amp;lt; square[i-1][1] &amp;lt;&amp;lt; &amp;quot; | &amp;quot; &amp;lt;&amp;lt; square[i-1][2] &amp;lt;&amp;lt; &amp;quot; |&amp;quot; &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot; +---+---+---+&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      }&lt;br /&gt;      &lt;span style="color:green;"&gt;//Check for an eventual winner of for a tie&lt;/span&gt;&lt;br /&gt;      for(int i=0;i&amp;lt;3;i++){&lt;br /&gt;         if(square[i][0] == square[i][1] &amp;amp;&amp;amp; square[i][1] == square[i][2] &amp;amp;&amp;amp; square[i][0] != ' '){&lt;br /&gt;            winner = square[i][0];&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      for(int i=0;i&amp;lt;3;i++){&lt;br /&gt;         if(square[0][i] == square[1][i] &amp;amp;&amp;amp; square[1][i] == square[2][i] &amp;amp;&amp;amp; square[0][i] != ' '){&lt;br /&gt;            winner = square[0][i];&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      if(square[0][0] == square[1][1] &amp;amp;&amp;amp; square[1][1] == square[2][2] &amp;amp;&amp;amp; square[0][0] != ' '){&lt;br /&gt;         winner = square[0][0];&lt;br /&gt;      }&lt;br /&gt;      if(square[0][2] == square[1][1] &amp;amp;&amp;amp; square[1][1] == square[2][0] &amp;amp;&amp;amp; square[0][2] != ' '){&lt;br /&gt;         winner = square[0][2];&lt;br /&gt;      }&lt;br /&gt;      if(square[0][0] == square[0][1] &amp;amp;&amp;amp; square[0][1] == square[0][2] &amp;amp;&amp;amp; square[0][2] == square[1][0] &amp;amp;&amp;amp; square[1][0] == square[1][1] &amp;amp;&amp;amp; square[1][1] == square[1][2] &amp;amp;&amp;amp; square[1][2] == square[2][0] &amp;amp;&amp;amp; square[2][0] == square[2][1] &amp;amp;&amp;amp; square[2][1] == square[2][2] &amp;amp;&amp;amp; square[0][0] != ' '){&lt;br /&gt;         winner = 't';&lt;br /&gt;      }&lt;br /&gt;      &lt;span style="color:green;"&gt;//If somebody won&lt;/span&gt;&lt;br /&gt;      if(winner == 'X' || winner == 'O'){&lt;br /&gt;         &lt;span style="color:green;"&gt;//Display congratulations message&lt;/span&gt;&lt;br /&gt;         cout &amp;lt;&amp;lt; &amp;quot;Congratulations! Player &amp;quot;;&lt;br /&gt;         if(winner == 'X'){&lt;br /&gt;            cout &amp;lt;&amp;lt; 1;&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            cout &amp;lt;&amp;lt; 2;&lt;br /&gt;         }&lt;br /&gt;         cout &amp;lt;&amp;lt; &amp;quot; is the winner!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      else if(winner == 't'){&lt;br /&gt;         &lt;span style="color:green;"&gt;//Display a message if it`s tie&lt;/span&gt;&lt;br /&gt;         cout &amp;lt;&amp;lt; &amp;quot;Tie!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      &lt;span style="color:green;"&gt;//If the game is not yet over show who`s the next player to move&lt;/span&gt;&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;Player &amp;quot;;&lt;br /&gt;      if(turn == 'X'){&lt;br /&gt;         cout &amp;lt;&amp;lt; 1;&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         cout &amp;lt;&amp;lt; 2;&lt;br /&gt;      } &lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;'s turn:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      &lt;span style="color:green;"&gt;//Loop until the player selects a valid square&lt;/span&gt;&lt;br /&gt;      validmove = false;&lt;br /&gt;      while(!validmove){&lt;br /&gt;         validrow = false;&lt;br /&gt;         &lt;span style="color:green;"&gt;//Loop until the player selects a valid row&lt;/span&gt;&lt;br /&gt;         while(!validrow){&lt;br /&gt;            cout &amp;lt;&amp;lt; &amp;quot;Row: &amp;quot;;&lt;br /&gt;            cin &amp;gt;&amp;gt; row;&lt;br /&gt;            if(row == 1 || row == 2 || row == 3){&lt;br /&gt;               validrow = true;&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Invalid row!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         validcolumn = false;&lt;br /&gt;         &lt;span style="color:green;"&gt;//Loop until the player selects a valid column&lt;/span&gt;&lt;br /&gt;         while(!validcolumn){&lt;br /&gt;            cout &amp;lt;&amp;lt; &amp;quot;Column: &amp;quot;;&lt;br /&gt;            cin &amp;gt;&amp;gt; column;&lt;br /&gt;            if(column == 1 || column == 2 || column == 3){&lt;br /&gt;               validcolumn = true;&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Invalid column!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         &lt;span style="color:green;"&gt;//Change the turn to the next player&lt;/span&gt;&lt;br /&gt;         if(square[row-1][column-1] == ' '){&lt;br /&gt;            square[row-1][column-1] = turn;&lt;br /&gt;            validmove = true;&lt;br /&gt;            if(turn == 'X'){&lt;br /&gt;               turn = 'O';&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               turn = 'X';&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         &lt;span style="color:green;"&gt;//If the selected square is occupied display a message and loop again&lt;/span&gt;&lt;br /&gt;         else{&lt;br /&gt;            cout &amp;lt;&amp;lt; &amp;quot;The selected square is occupied!&amp;quot; &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Select again:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;If something it`s not clear or you have any question just ask!&lt;br /&gt;If this is too advanced for you feel free to read my lessons or view the previous, simpler version of the game here: &lt;a href="http://www.codingmix.com/2010/07/simples-cplusplus-tic-tac-toe-game-ever_24.html"&gt;The simplest C++ Tic Tac Toe game ever&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-1501933207832143526?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sd6cQxsO_2WNFm8PzaMQvzyiDnA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sd6cQxsO_2WNFm8PzaMQvzyiDnA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sd6cQxsO_2WNFm8PzaMQvzyiDnA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sd6cQxsO_2WNFm8PzaMQvzyiDnA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/19jp-lgHtyc" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-01T13:45:13.711-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/very-simple-cplusplus-tic-tac-toe-game.html</feedburner:origLink></item><item><title>C++ Console Calculator v3</title><link>http://feedproxy.google.com/~r/CodingMix/~3/k6ppczSGwP8/cplusplus-console-calculator-v3.html</link><category>Cplusplus projects</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sat, 16 Oct 2010 07:13:34 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-232818944587829691</guid><description>This is a tutorial about creating the third version of my C++ Calculator (console application). Here are the first and second versions: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-console-calculator-v1.html"&gt;Calculator v1&lt;/a&gt; and &lt;a href="http://www.codingmix.com/2010/06/cplusplus-console-calculator-v2.html"&gt;Calculator v2&lt;/a&gt;. The previous versions of this applications are closed after displaying a warning message when an invalid operation is selected. In this version this was improved: the programs shows an error message and it asks again and again until a valid operation is selected. This version is also a bit shorter because in some places I`we used arrays and loops.&lt;div id="full-post"&gt;&lt;br /&gt;Required knowledge: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-4-variables.html"&gt;variables&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-5-inputoutput.html"&gt;input/output&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-6-ifelseelse-if_18.html"&gt;if/else/else if statements&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-7-switchcase-statement.html"&gt;switch/case statements&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/07/cplusplus-lesson-8-while-loop-and-for.html"&gt;loop&lt;/a&gt;, &lt;a href="http://www.codingmix.com/2010/09/cplusplus-lesson-9-arrays.html"&gt;arrays&lt;/a&gt;.&lt;br /&gt;Here is my code: &lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Enter the first number:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   int numone;&lt;br /&gt;   cin &amp;gt;&amp;gt; numone;&lt;br /&gt;   bool validselection = false;&lt;br /&gt;   char operation[] = {'*','/','+','-'};&lt;br /&gt;   int selectedoperation;&lt;br /&gt;   while(!validselection){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;Select an operation:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      for(int i=0;i&amp;lt;4;i++){&lt;br /&gt;         cout &amp;lt;&amp;lt; i+1 &amp;lt;&amp;lt; &amp;quot;. &amp;quot; &amp;lt;&amp;lt; operation[i] &amp;lt;&amp;lt; endl;&lt;br /&gt;      }&lt;br /&gt;      cin &amp;gt;&amp;gt; selectedoperation;&lt;br /&gt;      if(selectedoperation == 1 || selectedoperation == 2 || selectedoperation == 3 || selectedoperation == 4){&lt;br /&gt;         validselection = true;&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         cout &amp;lt;&amp;lt; &amp;quot;Invalid selection!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Enter the second number:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   int numtwo;&lt;br /&gt;   cin &amp;gt;&amp;gt; numtwo;&lt;br /&gt;   float result;&lt;br /&gt;   bool dividebyzero = false;&lt;br /&gt;   switch(selectedoperation){&lt;br /&gt;   case 1:&lt;br /&gt;      result = numone * numtwo;&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      if(numtwo == 0){&lt;br /&gt;         dividebyzero = true;&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         result = (float)numone / numtwo;&lt;br /&gt;      }&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      result = numone + numtwo;&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      result = numone - numtwo;&lt;br /&gt;      break;&lt;br /&gt;   }&lt;br /&gt;   if(!dividebyzero){&lt;br /&gt;      cout &amp;lt;&amp;lt; numone &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; operation[selectedoperation - 1] &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; numtwo &amp;lt;&amp;lt; &amp;quot; = &amp;quot; &amp;lt;&amp;lt; result &amp;lt;&amp;lt; endl;&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;Cannot divide by zero!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   }&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;This works almost the same way as the &lt;a href="http://www.codingmix.com/2010/06/cplusplus-console-calculator-v2.html"&gt;Calculator v2&lt;/a&gt;, the difference is that this version uses a loop and an array to display the available operations instead of multiple &lt;i&gt;cout&lt;/i&gt;`s and this whole part of code where the operation is asked is inside a loop and it loops until a valid operation is selected.&lt;br /&gt;This was the second version, but there will be more advanced ones, too.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-232818944587829691?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hAPj9jJ9leTgZr8GKwriFI2MW-Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hAPj9jJ9leTgZr8GKwriFI2MW-Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hAPj9jJ9leTgZr8GKwriFI2MW-Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hAPj9jJ9leTgZr8GKwriFI2MW-Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/k6ppczSGwP8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-16T07:13:34.571-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/cplusplus-console-calculator-v3.html</feedburner:origLink></item><item><title>Simple Chat script in PHP, MySQL and Ajax</title><link>http://feedproxy.google.com/~r/CodingMix/~3/BTBGl786ams/simple-chat-script-in-php-mysql-and.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 05 Nov 2010 04:58:55 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6620182635715936266</guid><description>In this tutorial I will show you how to create a simple but &lt;b&gt;very&lt;/b&gt; effective Chat script, and I said effective because unlike the most of the chat scripts this one deletes automatically the old messages from the database. Here is a live demo:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/chat/chat.php" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;&lt;br /&gt;The chat is refreshed automatically each 30 seconds.&lt;br /&gt;&lt;br /&gt;Let`s start: First we need to create a MySQL table with 4 fields: &lt;div class="code"&gt;time - the time when the message was posted (UNIX)&lt;br /&gt;name - the name of the author of the message&lt;br /&gt;ip - the ip of the author of the message&lt;br /&gt;message - the message text&lt;/div&gt;To create the table (I will call it &lt;i&gt;chat&lt;/i&gt;) I`we used the following file:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Create the table&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;create table chat(&lt;br /&gt;   time int(11) NOT NULL, &lt;br /&gt;   name varchar(30) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   message varchar(255) NOT NULL, &lt;br /&gt;   PRIMARY KEY (time)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;For the rest of the Chat script we will need 3 more files:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Let`s start with the chat.php what will contain the forms and all the Ajax scripts what will trigger the other 2 files: &lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.message {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:498px;&lt;br /&gt;   margin-bottom:5px;&lt;br /&gt;   border:1px solid #999;&lt;br /&gt;}&lt;br /&gt;.messagehead {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#FFC;&lt;br /&gt;   width:500px;&lt;br /&gt;}&lt;br /&gt;.messagecontent {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:496px;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;width:500px;margin:0 auto;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain the messages&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain an eventual error message&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;error&amp;quot; style=&amp;quot;width:500px;text-align:center;color:red;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div contains the forms and the send button&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;write&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&amp;gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;Name:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; onClick=&amp;quot;send();&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will display the messages&lt;/span&gt;&lt;br /&gt;function showmessages(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'show-message.php' file&lt;/span&gt;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;show-messages.php&amp;quot;,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;showmessages.php&amp;quot;,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Replace the content of the &lt;i&gt;messages&lt;/i&gt; with the response from the 'show-messages.php' file&lt;/span&gt;&lt;br /&gt;   document.getElementById('messages').innerHTML = xmlhttp.responseText;&lt;br /&gt;   &lt;span style="color:green;"&gt;//Repeat the function each 30 seconds&lt;/span&gt;&lt;br /&gt;   setTimeout('showmessages()',30000);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Start the &lt;i&gt;showmessages()&lt;/i&gt; function&lt;/span&gt;&lt;br /&gt;showmessages();&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will submit the message&lt;/span&gt;&lt;br /&gt;function send(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'send.php' file with all the required informations&lt;/span&gt;&lt;br /&gt;   var sendto = 'send.php?message=' + document.getElementById('message').value + '&amp;amp;name=' + document.getElementById('name').value;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   var error = '';&lt;br /&gt;   &lt;span style="color:green;"&gt;//If an error occurs the 'send.php' file send`s the number of the error and based on that number a message is displayed&lt;/span&gt;&lt;br /&gt;   switch(parseInt(xmlhttp.responseText)){&lt;br /&gt;   case 1:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      error = 'Don`t forget the message!';&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      error = 'The message is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 5:&lt;br /&gt;      error = 'Don`t forget the name!';&lt;br /&gt;      break;&lt;br /&gt;   case 6:&lt;br /&gt;      error = 'The name is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 7:&lt;br /&gt;      error = 'This name is already used by somebody else!';&lt;br /&gt;      break;&lt;br /&gt;   case 8:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;   }&lt;br /&gt;   if(error == ''){&lt;br /&gt;      document.getElementById('error').innerHTML = '';&lt;br /&gt;      showmessages();&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      document.getElementById('error').innerHTML = error;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (1);&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is empty and send the error code&lt;/span&gt;&lt;br /&gt;if(strlen($message) &amp;lt; 1){&lt;br /&gt;   echo 3;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($message) &amp;gt; 255){&lt;br /&gt;   echo 4;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is empty&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;lt; 1){&lt;br /&gt;   echo 5;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;gt; 29){&lt;br /&gt;   echo 6;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if the name is used by somebody else&lt;/span&gt;&lt;br /&gt;else if(mysql_num_rows(mysql_query(&amp;quot;select * from chat where name = '&amp;quot; . $name . &amp;quot;' and ip != '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 7;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//If everything is fine&lt;/span&gt;&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//This array contains the characters what will be removed from the message and name, because else somebody could send redirection script or links&lt;/span&gt;&lt;br /&gt;   $search = array(&amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;,&amp;quot;&amp;amp;lt;&amp;quot;);&lt;br /&gt;   &lt;span style="color:green;"&gt;//Insert a new row in the chat table&lt;/span&gt;&lt;br /&gt;   mysql_query(&amp;quot;insert into chat values ('&amp;quot; . time() . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$name) . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$message) . &amp;quot;')&amp;quot;) or die(8);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die(2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Get the first 10 messages ordered by time&lt;/span&gt;&lt;br /&gt;$result = mysql_query(&amp;quot;select * from chat order by time desc limit 0,10&amp;quot;);&lt;br /&gt;$messages = array();&lt;br /&gt;&lt;span style="color:green;"&gt;//Loop and get in an array all the rows until there are not more to get&lt;/span&gt;&lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Put the messages in divs and then in an array&lt;/span&gt;&lt;br /&gt;   $messages[] = &amp;quot;&amp;lt;div class='message'&amp;gt;&amp;lt;div class='messagehead'&amp;gt;&amp;quot; . $row[name] . &amp;quot; - &amp;quot; . date('g:i A M, d Y',$row[time]) . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='messagecontent'&amp;gt;&amp;quot; . $row[message] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;   &lt;span style="color:green;"&gt;//The last posts date&lt;/span&gt;&lt;br /&gt;   $old = $row[time];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Display the messages in an ascending order, so the newest message will be at the bottom&lt;/span&gt;&lt;br /&gt;for($i=9;$i&amp;gt;=0;$i--){&lt;br /&gt;   echo $messages[$i];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//This is the more important line, this deletes each message older then the 10th message ordered by time is deleted, so the table will never have to store more than 10 messages.&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;delete from chat where time &amp;lt; &amp;quot; . $old);&lt;br /&gt;?&amp;gt;&lt;/div&gt;And this is it. A very effect chat system what uses only 10 rows of a MySQL table. This chat system can be easily upgraded with admin options or IP bans, smileys and other stuff like this. If you have any question related to this chat system just ASK!&lt;br /&gt;&lt;br /&gt;UPDATE: a new version of this script (that works in IE) is ready: &lt;a href="http://www.codingmix.com/2010/11/cross-browser-chat-script-using-php.html" title="chat"&gt;Cross-browser chat&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6620182635715936266?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yp1wWx78SWDp5GU_4v5IQQmtgHw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yp1wWx78SWDp5GU_4v5IQQmtgHw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yp1wWx78SWDp5GU_4v5IQQmtgHw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yp1wWx78SWDp5GU_4v5IQQmtgHw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/BTBGl786ams" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-05T04:58:55.995-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">43</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/simple-chat-script-in-php-mysql-and.html</feedburner:origLink></item><item><title>Searching in a list with Javascript</title><link>http://feedproxy.google.com/~r/CodingMix/~3/yq4MdKnE6S8/searching-in-list-with-javascript.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 10 Sep 2010 08:07:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8039075891943670893</guid><description>In this tutorial I will show you how to create a script what searches in a list (li or table) for the inputted text at each press of a button. Because I can`t explain better what the script can do, here is an example: &lt;div id="full-post"&gt;&lt;div class="code"&gt;&lt;input type="text" id="searchbar" onKeyUp="searchit();"/&gt;&lt;ul style="list-style:none;margin:0px;padding:0 15px;"&gt;&lt;li class="search"&gt;Coffee&lt;/li&gt;&lt;li class="search"&gt;Milk&lt;/li&gt;&lt;li class="search"&gt;Chees&lt;/li&gt;&lt;li class="search"&gt;Tea&lt;/li&gt;&lt;li class="search"&gt;Orange&lt;/li&gt;&lt;li class="search"&gt;Sugar&lt;/li&gt;&lt;li class="search"&gt;Honey&lt;/li&gt;&lt;li class="search"&gt;Milkshake&lt;/li&gt;&lt;/ul&gt;&lt;script type="text/javascript"&gt;function searchit(){var keyword = document.getElementById('searchbar').value;for(var i=0;i&lt;=document.getElementsByTagName('li').length-1;i++){if(document.getElementsByTagName('li')[i].className == 'search'){if(document.getElementsByTagName('li')[i].innerHTML.toLowerCase().indexOf(keyword.toLowerCase()) == -1){document.getElementsByTagName('li')[i].style.height = '0px';}else{document.getElementsByTagName('li')[i].style.height = '20px';}}}}&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;How it works:&lt;/b&gt;&lt;br /&gt;The script loops through all the 'li' elements from the document and searches for the ones with class "search". From these 'li' elements it resizes to 0 pixels the ones what don`t contain the searched word, and it resizes to its original size the ones what contain the searched word: &lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.search {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;searchbar&amp;quot; onKeyUp=&amp;quot;searchit();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;ul style=&amp;quot;list-style:none;margin:0px;padding:0 15px;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Coffee&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Milk&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Chees&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Tea&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Orange&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Sugar&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Honey&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li class=&amp;quot;search&amp;quot;&amp;gt;Milkshake&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function searchit(){&lt;br /&gt;   var keyword = document.getElementById('searchbar').value;&lt;br /&gt;   for(var i=0;i&amp;lt;document.getElementsByTagName('li').length;i++){&lt;br /&gt;      if(document.getElementsByTagName('li')[i].className == 'search'){&lt;br /&gt;         if(document.getElementsByTagName('li')[i].innerHTML.toLowerCase().indexOf(keyword.toLowerCase()) == -1){&lt;br /&gt;            document.getElementsByTagName('li')[i].style.height = '0px';&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            document.getElementsByTagName('li')[i].style.height = '20px';&lt;br /&gt;         }&lt;br /&gt;      } &lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Note: The list must have the &lt;i&gt;overflow:hidden;&lt;/i&gt; property!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8039075891943670893?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/N_0WrQFaeL-ei7DgFogv904coSA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/N_0WrQFaeL-ei7DgFogv904coSA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/N_0WrQFaeL-ei7DgFogv904coSA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/N_0WrQFaeL-ei7DgFogv904coSA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/yq4MdKnE6S8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-10T08:07:00.333-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/searching-in-list-with-javascript.html</feedburner:origLink></item><item><title>C++ Lesson 9 - Arrays</title><link>http://feedproxy.google.com/~r/CodingMix/~3/RqoY7CwOovA/cplusplus-lesson-9-arrays.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 03 Sep 2010 08:46:32 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4106824301066022382</guid><description>Imagine a running competition with 5 runners. We want to store the seconds needed to finish the race for each runner. We would need 5 variables, one for each runner:&lt;div id="full-post"&gt;&lt;div class="code"&gt;int runner1 = 200;&lt;br /&gt;int runner2 = 105;&lt;br /&gt;int runner3 = 340;&lt;br /&gt;int runner4 = 243;&lt;br /&gt;int runner5 = 345;&lt;/div&gt;The disadvantage of the above code is that we can`t loop through the results. In this situation the best method is to use an &lt;b&gt;array&lt;/b&gt;.&lt;br /&gt;An array would look in the following way:&lt;div class="code"&gt;runner[0] = 200;&lt;br /&gt;runner[1] = 105;&lt;br /&gt;runner[2] = 340;&lt;br /&gt;runner[3] = 243;&lt;br /&gt;runner[4] = 345;&lt;/div&gt;&lt;br /&gt;Those numbers in the brackets are the &lt;b&gt;index&lt;/b&gt; number, and these numbers are showing the position of a given value in the array. &lt;br /&gt;&lt;b&gt;Initializing arrays&lt;/b&gt;&lt;br /&gt;An array can be initialized in three different ways:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1.&lt;/b&gt; Syntax:&lt;div class="code"&gt;type identifier[max_elements_number];&lt;/div&gt;Example: &lt;div class="code"&gt;int runner[5];&lt;br /&gt;runner[0] = 200;&lt;br /&gt;runner[1] = 105;&lt;br /&gt;runner[2] = 340;&lt;br /&gt;runner[3] = 243;&lt;br /&gt;runner[4] = 345&lt;/div&gt; &lt;br /&gt;&lt;b&gt;2.&lt;/b&gt; Syntax:&lt;div class="code"&gt;type identifier[max_elements_number] = {element_1,element_2,element_max_elements_numbe};&lt;/div&gt;Example:&lt;div class="code"&gt;int runner[5] = {200,105,340,243,345};&lt;/div&gt;The number of elements can be fewer than the max_elements_number, but not greater.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;3.&lt;/b&gt; Syntax:&lt;div class="code"&gt;type identifier[] = {element_1,element_2,element_n};&lt;/div&gt;Example: &lt;div class="code"&gt;int runner[] = {200,105,340,243,345};&lt;/div&gt;The maximum number of elements is generated automatically based on the added elements number.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;runner&lt;/i&gt; array look in the following way for the computer:&lt;div class="code"&gt;&lt;div style="float:left;"&gt;runner = &lt;/div&gt;&lt;table style="float:left;" width="200" border="1"&gt;&lt;tr&gt;&lt;td&gt;200&lt;/td&gt;&lt;td&gt;105&lt;/td&gt;&lt;td&gt;340&lt;/td&gt;&lt;td&gt;243&lt;/td&gt;&lt;td&gt;345&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;div style="float:left;width:520px;"&gt;                 (0)     (1)     (2)     (3)     (4)&lt;/div&gt;&lt;/div&gt;This is an &lt;b&gt;one-dimensional array&lt;/b&gt;, because it has only one index number. So, yes an array can have more than one index. Now you probably ask, why to use more than one indexes ?&lt;br /&gt;&lt;br /&gt;Well, let`s continue the idea of a running competition. Now imagine that you need to store the timings of the last 3 competitions for our 5 runners. The new array would look like this: &lt;div class="code"&gt;&lt;div style="float:left;"&gt;runner = &lt;/div&gt;&lt;table style="float:left;" width="200" border="1"&gt;&lt;tr&gt;&lt;td&gt;200&lt;/td&gt;&lt;td&gt;105&lt;/td&gt;&lt;td&gt;340&lt;/td&gt;&lt;td&gt;243&lt;/td&gt;&lt;td&gt;345&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;223&lt;/td&gt;&lt;td&gt;324&lt;/td&gt;&lt;td&gt;323&lt;/td&gt;&lt;td&gt;454&lt;/td&gt;&lt;td&gt;123&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;245&lt;/td&gt;&lt;td&gt;203&lt;/td&gt;&lt;td&gt;150&lt;/td&gt;&lt;td&gt;340&lt;/td&gt;&lt;td&gt;311&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;div style="float:left;line-height:27px;"&gt;(0)&lt;br /&gt;(1)&lt;br /&gt;(2)&lt;/div&gt;&lt;div style="float:left;width:520px;"&gt;                 (0)     (1)     (2)     (3)     (4)&lt;/div&gt;&lt;/div&gt;So we have 5 runners and a column for each of them. We have 3 competitions and a row for each of them. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Getting a value from this table&lt;/b&gt; &lt;br /&gt;Let`s say we need the timing of runner 2`s from the competition 1: &lt;div class="code"&gt;cout &lt;&lt; runner[2][1]; //323&lt;/div&gt; &lt;br /&gt;&lt;b&gt;Initializing a multi-dimensional array&lt;/b&gt;&lt;br /&gt;Because this is very similar to the one-dimensional arrays I will show you just some example:&lt;div class="code"&gt;int runner[5][3];&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;int runner[5][3] = {{200,223,245},{105,324,203},{340,323,150},{243,454,340},{345,123,311}};&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;int runner[][3] = {{200,223,245},{105,324,203},{340,323,150},{243,454,340},{345,123,311}};&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt;: With multi-dimensional arrays only the first index can be leaved blank!&lt;/div&gt;&lt;br /&gt;The max_elements_number needs to be a &lt;b&gt;constant&lt;/b&gt; value, this can`t be changed during the program runs. The first element of an array is always the 0th element.&lt;br /&gt;&lt;br /&gt;Here is an example of how useful can arrays be: &lt;div class="code"&gt;#include &lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int number[11];&lt;br /&gt;   for(int i=0;i&lt;=10;i++){&lt;br /&gt;      number[i] = i;&lt;br /&gt;   }&lt;br /&gt;   for(int i=0;i&lt;=10;i++){&lt;br /&gt;      cout &lt;&lt; number[i] &lt;&lt; endl;&lt;br /&gt;   }&lt;br /&gt;   system("pause");&lt;br /&gt;}&lt;/div&gt;The above program simply loads an array with numbers from 0 to 10 (11 elements) and then writes out the numbers. Using simple variables this would not be possible, we would need 11 variables and many lines of code for the same result.&lt;br /&gt;&lt;br /&gt;Next lesson: Coming soon&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/07/cplusplus-lesson-8-while-loop-and-for.html"&gt;C++ Lesson 8 - while loop and for loop&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4106824301066022382?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bBshAWFBRR4a-8IAsh_GrjTlfio/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bBshAWFBRR4a-8IAsh_GrjTlfio/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bBshAWFBRR4a-8IAsh_GrjTlfio/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bBshAWFBRR4a-8IAsh_GrjTlfio/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/RqoY7CwOovA" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-03T08:46:32.000-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/cplusplus-lesson-9-arrays.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 6</title><link>http://feedproxy.google.com/~r/CodingMix/~3/dtw0GOgFNZw/creating-javascript-slideshow-part-6.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 29 Aug 2010 05:44:16 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8299546093059820701</guid><description>Before reading this please read the &lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html" title="Javascript slideshow"&gt;first parts&lt;/a&gt; of the tutorial.&lt;br /&gt;This is the last part of this tutorials series. In this part of the tutorial we will finish the slideshow. &lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;Positioning the buttons in a better way&lt;/b&gt;&lt;br /&gt;Let`s make the slideshow controls look better. My idea is to place the "Prev" button in the left corner, the "Slow Medium Fast" button in the middle of the div and the "Next" button in the right corner, each with a margin of 5px. Here is how I did:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&lt;span style="color:red;"&gt;text-align: center;&lt;/span&gt;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot; style=&amp;quot;&lt;span style="color:red;"&gt;float:left;margin-left:5px;&lt;/span&gt;&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot; style=&amp;quot;margin:0 1px;&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot; style=&amp;quot;&lt;span style="color:red;"&gt;float:right;margin-right:5px;&lt;/span&gt;&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Showing the current image number&lt;/b&gt;&lt;br /&gt;This will be the last step in finishing the slideshow. Now we will place a message like this: 3/5 ,the number of the current image/images number.&lt;br /&gt;I think it would be the best to place it in the right upper corner of the slideshow with a black transparent background (so we will need two div`s, one for the background and one for the numbers, just like at the controls).&lt;br /&gt;First let`s create the two divs:&lt;div class="code"&gt;&amp;lt;div id=&amp;quot;imagesnumberbg&amp;quot; style=&amp;quot;background:black;position:absolute;width:50px;height:20px;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;imagesnumber&amp;quot; style=&amp;quot;position:absolute;width:50px;height:20px;text-align:center;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/div&gt;Place them right before the &lt;i&gt;loadingimage&lt;/i&gt; div.&lt;br /&gt;For now the two divs are empty and are placed in the left corner. Because the &lt;i&gt;position:absolute;&lt;/i&gt; property we can`t use the &lt;i&gt;float:right;&lt;/i&gt; property, instead we will need to use the &lt;i&gt;margin-left:&lt;/i&gt; property, but we need to calculate the distance required. &lt;br /&gt;We will do this by adding some code to the &lt;i&gt;changeimage&lt;/i&gt; function. Here will come the code what will change the numbers, too. This entire piece of code will look like this: &lt;div class="code"&gt;var requiredmargin = parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('imagesnumberbg').style.width);&lt;br /&gt;   document.getElementById('imagesnumberbg').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').innerHTML = currentimage + '/' + (images.length - 1);&lt;/div&gt;&lt;br /&gt;&lt;b&gt;After all of these 6 parts of creating and styling the slideshow my code looks in the following way, yours should be the same:&lt;/b&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;imagesnumberbg&amp;quot; style=&amp;quot;background:black;position:absolute;width:50px;height:20px;filter:alpha(opacity=60);opacity:0.6;margin-left:400px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;imagesnumber&amp;quot; style=&amp;quot;position:absolute;width:50px;height:20px;text-align:center;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;text-align: center;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot; style=&amp;quot;float:left;margin-left:5px;&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot; style=&amp;quot;margin:0 1px;&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot; style=&amp;quot;float:right;margin-right:5px;&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:red;"&gt;var requiredmargin = parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('imagesnumberbg').style.width);&lt;br /&gt;   document.getElementById('imagesnumberbg').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').style.marginLeft = requiredmargin + 'px';&lt;br /&gt;   document.getElementById('imagesnumber').innerHTML = currentimage + '/' + (images.length - 1);&lt;/span&gt;&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);&lt;br /&gt;}&lt;br /&gt;function stopsliding(){&lt;br /&gt;   clearTimeout(timeout);&lt;br /&gt;   document.getElementById('startslideshowbutton').innerHTML = &amp;quot;&amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);\&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);\&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);\&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;b&gt;And here is the slideshow:&lt;/b&gt; &lt;a onClick="previewslideshow();" style="color:green;font-weight:bold;"&gt;Start it&lt;/a&gt;&lt;br /&gt;(In the preview the Stop slideshow button is not working because the new window is written by Javascript and it can`t format well all the quotes - but else it works :D )&lt;br /&gt;If something is not working or just have a question, don`t hesitate, ASK!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8299546093059820701?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/90drDuH1834zK66RC2quseLdsSQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/90drDuH1834zK66RC2quseLdsSQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/90drDuH1834zK66RC2quseLdsSQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/90drDuH1834zK66RC2quseLdsSQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/dtw0GOgFNZw" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-29T05:44:16.893-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-6.html</feedburner:origLink></item><item><title>Javascript - get elements by class</title><link>http://feedproxy.google.com/~r/CodingMix/~3/1f84c4_20cs/javascript-get-elements-by-class.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Thu, 09 Sep 2010 14:48:23 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6053498948888109142</guid><description>I will show you two ways to get an element by class: using getElementsByTagName or creating a getElementByClass function:&lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;1. Using getElementsByTagName&lt;/b&gt;&lt;br /&gt;This code loops through each element of the page and check`s it`s class name:&lt;br /&gt;&lt;div class="code"&gt;for(var i=0;i&amp;lt;document.getElementsByTagName('*').length;i++){&lt;br /&gt;   if(document.getElementsByTagName('*')[i].className == 'YOUR-CLASS'){&lt;br /&gt;      document.getElementsByTagName('*')[i].style.backgroundColor = 'black';&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;2. Creating a getElementsByClass function&lt;/b&gt;&lt;br /&gt;This code creates the getElementsByClass function what returns an array of elements with the selected class name:&lt;div class="code"&gt;document.getElementsByClass = function(class){&lt;br /&gt;   var itemsfound = new Array;&lt;br /&gt;   var elements = document.getElementsByTagName('*');&lt;br /&gt;   for(var i=0;i&amp;lt;elements.length;i++){&lt;br /&gt;      if(elements[i].className == class){&lt;br /&gt;         itemsfound.push(elements[i]);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   return itemsfound;&lt;br /&gt;}&lt;/div&gt;Use it in the following way to select only the element with the specified index:&lt;div class="code"&gt;document.getElementsByClass('YOUR-CLASS')[0].style.backgroundColor = 'black';&lt;/div&gt;Or use this if you want to select each element:&lt;div class="code"&gt;for(var i=0;i&lt;=document.getElementsByClass('YOUR-CLASS').length;i++){&lt;br /&gt; document.getElementsByClass('YOUR-CLASS')[i].style.backgroundColor = 'black';&lt;br /&gt;}&lt;/div&gt;Note: Javascript is case sensitive&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6053498948888109142?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/81JApDj8V0-JuEkBjS-H_sYa-JE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/81JApDj8V0-JuEkBjS-H_sYa-JE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/81JApDj8V0-JuEkBjS-H_sYa-JE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/81JApDj8V0-JuEkBjS-H_sYa-JE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/1f84c4_20cs" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-09T14:48:23.976-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/javascript-get-elements-by-class.html</feedburner:origLink></item><item><title>Creating a Javascript Slideshow part 5</title><link>http://feedproxy.google.com/~r/CodingMix/~3/29JMLUz9Rrg/creating-javascript-slideshow-part-5.html</link><category>Javascript tutorials</category><category>Javascript</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 29 Aug 2010 05:32:06 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6046868732677861566</guid><description>Before reading this please read the first parts of this tutorials: &lt;a href="http://www.codingmix.com/2010/07/how-to-create-slideshow-without-jquery.html" title="slideshow"&gt;Part 1&lt;/a&gt;&lt;br /&gt;In this part we will add an automatic sliding option to our slideshow, whit 3 speed levels: slow, medium, fast. &lt;div id="full-post"&gt;Let`s make it:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Sliding the images automatically&lt;/b&gt;&lt;br /&gt;To slide the images automatically we need a function (name it &lt;i&gt;slideautomatically&lt;/i&gt;) what will start the &lt;i&gt;changeimage&lt;/i&gt; function again and again with a delays. We will make it using the &lt;i&gt;setTimeout&lt;/i&gt; funtion and we will adjust the speed by changing the delay (in milliseconds) between each run of the function. This function will be triggered by the three buttons: Slow, Medium and the Fast buttons using &lt;i&gt;onClick&lt;/i&gt; events. Each of these buttons will have as &lt;i&gt;parameter&lt;/i&gt; the delay between each run of the function in milliseconds. Name tha parameter &lt;i&gt;timeinterval&lt;/i&gt;&lt;br /&gt;The function should look like this: &lt;div class="code"&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);   &lt;br /&gt;}&lt;/div&gt;Note: I have used a variable to store the timeout, because later will need to clear it.&lt;br /&gt;Now we need to create the buttons what will start this function:&lt;div class="code"&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;/div&gt;Place it between the Prev and Next buttons. &lt;br /&gt;&lt;br /&gt;After editing it my code look like this:&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Now the images are changed automatically but now we need a way to stop it. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Stop it&lt;/b&gt;&lt;br /&gt;To stop the automatic sliding we will need first a button to stop it by triggering a function. Call this function &lt;i&gt;stopsliding&lt;/i&gt;. We will place this button in the place of the "Slow Medium Fast" button by changing the content of the &lt;i&gt;startslideshowbutton&lt;/i&gt; span when the automatic sliding starts. We will change the content of the &lt;i&gt;startslideshowbutton&lt;/i&gt; span by changing the &lt;i&gt;onClick &lt;/i&gt; event of the "Slow Medium Fast" buttons from this: &lt;div class="code"&gt;onClick="slideautomatically(8000);"&lt;br /&gt;onClick="slideautomatically(4000);"&lt;br /&gt;onClick="slideautomatically(2000);"&lt;/div&gt;to this:&lt;div class="code"&gt;onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&lt;br /&gt;onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&lt;br /&gt;onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&lt;/div&gt;Note: The &lt;b&gt;&amp;amp;quot;&lt;/b&gt; character is used to replace a double quote. Because this is an inline Javascript event we &lt;b&gt;can`t&lt;/b&gt; use the &lt;b&gt;\"&lt;/b&gt; character instead.&lt;br /&gt;&lt;br /&gt;Now we just need to create the &lt;i&gt;stopsliding&lt;/i&gt; function:&lt;div class="code"&gt;function stopsliding(){&lt;br /&gt;   clearTimeout(timeout);&lt;br /&gt;   document.getElementById('startslideshowbutton').innerHTML = &amp;quot;&amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);\&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);\&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);\&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;/div&gt;The above function first clears the timeout so stops the automatic sliding and then it replaces the "Stop slideshow" button with the "Slow Medium Fast" buttons.&lt;br /&gt;&lt;br /&gt;Here is my code, yours should look the same: &lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshow&amp;quot; style=&amp;quot;width:400px;overflow:hidden;background:black;color:white;&amp;quot; onMouseOver=&amp;quot;showcontrols();&amp;quot; onMouseOut=&amp;quot;hidecontrols();&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;loadingimage&amp;quot; style=&amp;quot;background:black;position:absolute;width:100px;height:20px;text-align:center;filter:alpha(opacity=60);opacity:0.6;&amp;quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowimage&amp;quot; style=&amp;quot;height:301px;width:400px;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrolsbg&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;background:black;filter:alpha(opacity=60);opacity:0.6;z-index:-1;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;slideshowcontrols&amp;quot; style=&amp;quot;width:400px;overflow:hidden;position:absolute;height:20px;margin:-20px 0;z-index:-1;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(-1);&amp;quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;span id=&amp;quot;startslideshowbutton&amp;quot;&amp;gt;&amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a onClick=&amp;quot;changeimage(1);&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;var images = new Array;&lt;br /&gt;images[1] = &amp;quot;http://www.carpages.co.uk/guide/@images/skoda/skoda-octavia.jpg&amp;quot;;&lt;br /&gt;images[2] = &amp;quot;http://image.automotive.com/f/reviews/driven/11352663+pheader/0812_01_z+2009_volkswagen_jetta_tDI+front_three_quarter_view.jpg&amp;quot;;&lt;br /&gt;images[3] = &amp;quot;http://www.carautoportal.com/car-images/audi/audi-r8-car.jpg&amp;quot;;&lt;br /&gt;images[4] = &amp;quot;http://www.roadfly.com/new-cars/wp-content/uploads/gallery/2008-mercedes-benz-c-class/2008-mercedes-benz-C350-sport.jpg&amp;quot;;&lt;br /&gt;images[5] = &amp;quot;http://capital.automotive-enewsletters.com/wp-content/uploads/2009/12/bmw.jpg&amp;quot;;&lt;br /&gt;var currentimage = 1;&lt;br /&gt;document.getElementById('loadingimage').style.margin = ((parseInt(document.getElementById('slideshowimage').style.height) - parseInt(document.getElementById('loadingimage').style.height))/2 + 'px ' + (parseInt(document.getElementById('slideshowimage').style.width) - parseInt(document.getElementById('loadingimage').style.width))/2 + 'px');&lt;br /&gt;function changeimage(change){&lt;br /&gt;   currentimage += change;&lt;br /&gt;   if(currentimage &amp;gt; images.length - 1){&lt;br /&gt;      currentimage = 1;&lt;br /&gt;   }&lt;br /&gt;   else if(currentimage &amp;lt; 1){&lt;br /&gt;      currentimage = images.length - 1;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('slideshowimage').innerHTML = '&amp;lt;img id=&amp;quot;image&amp;quot; width=&amp;quot;' + document.getElementById('slideshowimage').style.width +'&amp;quot; src=&amp;quot;' + images[currentimage] + '&amp;quot;/&amp;gt;';&lt;br /&gt;   waitimage();&lt;br /&gt;}&lt;br /&gt;function waitimage(){&lt;br /&gt;   if(document.getElementById('image').complete){&lt;br /&gt;      positioningimage();&lt;br /&gt;      return;&lt;br /&gt;   }&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = 1;&lt;br /&gt;   setTimeout('waitimage()',250);&lt;br /&gt;}&lt;br /&gt;function positioningimage(){&lt;br /&gt;   document.getElementById('image').style.marginTop = (parseInt(document.getElementById('slideshowimage').style.height) - document.getElementById('image').height) / 2 + 'px';&lt;br /&gt;   document.getElementById('loadingimage').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function showcontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = 1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = 1;&lt;br /&gt;}&lt;br /&gt;function hidecontrols(){&lt;br /&gt;   document.getElementById('slideshowcontrols').style.zIndex = -1;&lt;br /&gt;   document.getElementById('slideshowcontrolsbg').style.zIndex = -1;&lt;br /&gt;}&lt;br /&gt;function slideautomatically(timeinterval){&lt;br /&gt;   changeimage(1);&lt;br /&gt;   timeout = setTimeout(function(){slideautomatically(timeinterval)},timeinterval);&lt;br /&gt;}&lt;br /&gt;function stopsliding(){&lt;br /&gt;   clearTimeout(timeout);&lt;br /&gt;   document.getElementById('startslideshowbutton').innerHTML = &amp;quot;&amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(8000);\&amp;quot;&amp;gt;Slow&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(4000);\&amp;quot;&amp;gt;Medium&amp;lt;/a&amp;gt; &amp;lt;a onClick=\&amp;quot;this.parentNode.innerHTML='&amp;lt;a onClick=&amp;amp;quot;stopsliding();&amp;amp;quot;&amp;gt;Stop slideshow&amp;lt;/a&amp;gt;';slideautomatically(2000);\&amp;quot;&amp;gt;Fast&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;changeimage(0);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;If something is not clear ASK ME!&lt;br /&gt;Continue to &lt;a href="http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-6.html"&gt;part 6&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6046868732677861566?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ocI3J4kIBcTpBKSguXA_AhO_mTE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ocI3J4kIBcTpBKSguXA_AhO_mTE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ocI3J4kIBcTpBKSguXA_AhO_mTE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ocI3J4kIBcTpBKSguXA_AhO_mTE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingMix/~4/29JMLUz9Rrg" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-29T05:32:06.956-07:00</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.codingmix.com/2010/08/creating-javascript-slideshow-part-5.html</feedburner:origLink></item></channel></rss>

