{"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<\/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<\/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 These lines simply tell our file where to get the JavaScript that we will be calling for. <\/p>\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<\/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":"\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
\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[\/sourcecode]\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[sourcecode language='php']\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[0];\r\n[\/sourcecode]\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[sourcecode language='php']\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[0];\r\n[\/sourcecode]\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[sourcecode language='php']\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