{"id":1633,"date":"2008-08-13T05:10:06","date_gmt":"2008-08-13T09:10:06","guid":{"rendered":"http:\/\/teamtutorials.com\/?p=1633"},"modified":"2008-10-26T14:45:01","modified_gmt":"2008-10-26T18:45:01","slug":"javascript-progress-bar-2","status":"publish","type":"post","link":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2","title":{"rendered":"JavaScript Progress Bar 2"},"content":{"rendered":"

This tutorial will walk you through configuring a JavaScript based progress bar that can triggered by several things. The last tutorial I did, I mentioned doing it with PHP and the results of a query. That is what this tutorial is going to be about. For this tutorial it would be helpful to have a decent amount of entries in the table we will be working with. To assist with this I have uploaded a text file<\/a> with a query in it to insert 150 rows into a table. Let\u2019s get started:<\/p>\n

Go to bram.us<\/a> to download the files that will make the loading bar work. <\/p>\n\"javascript_progress_bar_2_01\"<\/a>\n

First you will be at the site to download the software. Click on the link to download the latest version. Save the file to your computer somewhere where you can access it. It will be in ZIP format so you will need to extract the files within it.<\/p>\n\"javascript_progress_bar_2_02\"<\/a>\n

You should have a folder that contains these folders and the one file. That html file is the demo that is given with the progress bar. You can delete it or you can keep it for you to look at later if you ever want to go back and look at how it works. We, however, will be making a new file from scratch to call these scripts. Let\u2019s make a new file and call it progress.php. Let\u2019s start coding that file.<\/p>\n

\r\n<script type="text\/javascript" src="js\/prototype\/prototype.js"><\/script>\r\n<script type="text\/javascript" src="js\/bramus\/jsProgressBarHandler.js"><\/script>\r\n<\/pre>\n

These lines simply tell our file where to get the JavaScript that we will be calling for. <\/p>\n

\r\n<?php\r\n\r\n$conn = mysql_connect ("localhost","username","password") or die ('cannot connect to database error: '.mysql_error());\r\nmysql_select_db ('dbname');\r\n&#91;\/sourcecode&#93;\r\n\r\nThis starts the section of php coding and the initializes the connection to the database. Remember to change the username, password, and dbname fields to what they are on your database.\r\n\r\n&#91;sourcecode language='php'&#93;\r\n$sql="SELECT count(*) from `tutorial`.`tutorial`";\r\n$query = mysql_query($sql);\r\n$row = mysql_fetch_row($query);\r\n$total = $row&#91;0&#93;;\r\n&#91;\/sourcecode&#93;\r\n\r\nThis select returns a count of all the records in the database. In this case (if you used the text file supplied) is 150 records. \r\n\r\n&#91;sourcecode language='php'&#93;\r\n$sql2="SELECT count(*) from `tutorial`.`tutorial` where `updates` = '1'";\r\n$query2 = mysql_query($sql2);\r\n$row2 = mysql_fetch_row($query2);\r\n$signed = $row2&#91;0&#93;;\r\n&#91;\/sourcecode&#93;\r\n\r\nThis select generates a count of how many people have signed up to receive updates about the site. This is indicated by the updates column being a 1. \r\n\r\n&#91;sourcecode language='php'&#93;\r\n$percent = $total - $signed;\r\n$percent = ($percent\/$total) * 100;\r\n\r\necho "<H2> Percentage of people signed up for updates <\/H2>";\r\necho "<span style='color:#006600;font-weight:bold;'>Percent Completed<\/span> <br\/>";\r\necho "<span class='progressBar' id='element1'>$percent<\/span>";\r\n\r\n?>\r\n<\/pre>\n

Next, we do the math to figure out the percentage. We take the total record number and subtract the count of those signed up and that gives us the number that aren\u2019t. Then we divide that number by the total and multiply 100 (the progress bar requires a full number and not a decimal). If the value is not a whole number the bar will round to the nearest whole number. Then we show our header for the bar and then show the percent completed logo. Finally, we create the bar with the variable that is calculated by the math. <\/p>\n\"javascript_progress_bar_2_03\"<\/a>\n

If you open the file in the browse it will run the queries and show the percentage automatically. That concludes this tutorial. I hope you enjoyed it and it was easy to follow. Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"

This tutorial will walk you through configuring a JavaScript based progress bar that can triggered by several things. The last tutorial I did, I mentioned doing it with PHP and the results of a query. That is what this tutorial is going to be about.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[30,24,17],"tags":[50,51,55],"yoast_head":"\nJavaScript Progress Bar 2<\/title>\n<meta name=\"description\" content=\"This tutorial will walk you through configuring a JavaScript based progress bar that can triggered by several things. The last tutorial I did, I mentioned doing it with PHP and the results of a query. That is what this tutorial is going to be about.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mike Maguire\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/teamtutorials.com\/#website\",\"url\":\"https:\/\/teamtutorials.com\/\",\"name\":\"Team Tutorials\",\"description\":\"Learn something new today\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/teamtutorials.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/08\/javascript_progress_bar_2_01.jpg\",\"contentUrl\":\"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/08\/javascript_progress_bar_2_01.jpg\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#webpage\",\"url\":\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2\",\"name\":\"JavaScript Progress Bar 2\",\"isPartOf\":{\"@id\":\"https:\/\/teamtutorials.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#primaryimage\"},\"datePublished\":\"2008-08-13T09:10:06+00:00\",\"dateModified\":\"2008-10-26T18:45:01+00:00\",\"author\":{\"@id\":\"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b\"},\"description\":\"This tutorial will walk you through configuring a JavaScript based progress bar that can triggered by several things. The last tutorial I did, I mentioned doing it with PHP and the results of a query. That is what this tutorial is going to be about.\",\"breadcrumb\":{\"@id\":\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/teamtutorials.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Progress Bar 2\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b\",\"name\":\"Mike Maguire\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/teamtutorials.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r\",\"caption\":\"Mike Maguire\"},\"sameAs\":[\"http:\/\/mikemaguire.me\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Progress Bar 2","description":"This tutorial will walk you through configuring a JavaScript based progress bar that can triggered by several things. The last tutorial I did, I mentioned doing it with PHP and the results of a query. That is what this tutorial is going to be about.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2","twitter_misc":{"Written by":"Mike Maguire","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/teamtutorials.com\/#website","url":"https:\/\/teamtutorials.com\/","name":"Team Tutorials","description":"Learn something new today","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/teamtutorials.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#primaryimage","inLanguage":"en-US","url":"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/08\/javascript_progress_bar_2_01.jpg","contentUrl":"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/08\/javascript_progress_bar_2_01.jpg"},{"@type":"WebPage","@id":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#webpage","url":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2","name":"JavaScript Progress Bar 2","isPartOf":{"@id":"https:\/\/teamtutorials.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#primaryimage"},"datePublished":"2008-08-13T09:10:06+00:00","dateModified":"2008-10-26T18:45:01+00:00","author":{"@id":"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b"},"description":"This tutorial will walk you through configuring a JavaScript based progress bar that can triggered by several things. The last tutorial I did, I mentioned doing it with PHP and the results of a query. That is what this tutorial is going to be about.","breadcrumb":{"@id":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/teamtutorials.com\/web-development-tutorials\/javascript-progress-bar-2#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/teamtutorials.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript Progress Bar 2"}]},{"@type":"Person","@id":"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b","name":"Mike Maguire","image":{"@type":"ImageObject","@id":"https:\/\/teamtutorials.com\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r","caption":"Mike Maguire"},"sameAs":["http:\/\/mikemaguire.me"]}]}},"_links":{"self":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/posts\/1633"}],"collection":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/comments?post=1633"}],"version-history":[{"count":0,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/posts\/1633\/revisions"}],"wp:attachment":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/media?parent=1633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/categories?post=1633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/tags?post=1633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}