ctcp Posted October 28, 2011 Share Posted October 28, 2011 $query_for_result=mysql_query("SELECT * FROM $db_tb_name LIMIT 0, 1 "); while($data_fetch=mysql_fetch_array($query_for_result)) { $c=$data_fetch['total_credits']; $l=$data_fetch['total_likes']; $stats = $l / $c * 100 ; include('progress.php'); $progress6 = new Progress(); $progress6->percent = $stats . "% Campaign progress"; $progress6->width = 800; $progress6->height = 22; $progress6->style = "image"; $progress6->makeBar(); } mysql_close(); im using faction to show progress bar for record can sombady help me how to loop this for all records? Quote Link to comment https://forums.phpfreaks.com/topic/249988-how-to-loop/ Share on other sites More sharing options...
Psycho Posted October 28, 2011 Share Posted October 28, 2011 Not sure what you mean. You already have a while loop to process all the records in the result set. You will need to provide more information. Are you getting errors? What is the output like now and how do you want it different? You are using a custom class for some of the functionality so we have no idea what $progress6->makeBar() is even doing. Quote Link to comment https://forums.phpfreaks.com/topic/249988-how-to-loop/#findComment-1283028 Share on other sites More sharing options...
ctcp Posted October 28, 2011 Author Share Posted October 28, 2011 progress.php <?php class Progress { // Default values public $percent = 0; public $width = 200; public $height = 20; public $style = ""; public $color = "transparent"; public $sColor = "transparent"; public $borderColor = "#000"; public $image = "images/pbar-ani.gif"; public $showPercent = true; public function makeBar() { // Output the bar echo '<div id="progress" style="width:'.$this->width.'px;height:'.$this->height.'px;background-color:'.$this->sColor.'; border:solid 1px '.$this->borderColor.'">'; echo '<div id="progress-value" style="width:'.$this->percent.'%;height:'.$this->height.'px;background-color:'.$this->color.';'; if($this->style == "image") { echo 'background-image:url('.$this->image.'); background-repeat:repeat-x;border:solid 1px '.$this->borderColor.'; margin-top:-1px; margin-left:-1px;">'; } else { echo 'border:solid 1px '.$this->borderColor.';margin-top:-1px;margin-left:-1px;">'; } if($this->showPercent){ // Set fontsize $this->fontsize = $this->height*5; echo '<center><span style="font-size:'.$this->fontsize.'%">'.$this->percent.'%</span></center>'; } echo '</div></div>'; } } ?> index.php <?php $query_for_result=mysql_query("SELECT * FROM $db_tb_name "); echo "<h2>Search Results</h2><ol>"; while($data_fetch=mysql_fetch_array($query_for_result)) { $c=$data_fetch['total_credits']; $l=$data_fetch['total_likes']; $stats = $l / $c * 100 ; //echo "$stats % Complete"; //echo $c; //echo $l; include('progress.php'); $progress6 = new Progress(); echo "<li>"; echo " $stats % Campaign progress"; echo "</li><hr/>"; $progress6->percent = $stats; $progress6->width = 850; $progress6->height = 22; $progress6->style = "image"; $progress6->makeBar(); } echo "</ol>"; mysql_close(); ?> i got error on line 3 progress.php Fatal error: Cannot redeclare class Progress can sombady help me how to loop this? Quote Link to comment https://forums.phpfreaks.com/topic/249988-how-to-loop/#findComment-1283112 Share on other sites More sharing options...
Psycho Posted October 28, 2011 Share Posted October 28, 2011 The error is self explanatory. You are trying to include progress.php on every iteration of the loop - thus it is trying to redeclare the class. You only need to include() the class ONE TIME. So, you can either move the include() to occur before the loop starts or you cna change it to an include_once() - or both. Quote Link to comment https://forums.phpfreaks.com/topic/249988-how-to-loop/#findComment-1283117 Share on other sites More sharing options...
ctcp Posted October 28, 2011 Author Share Posted October 28, 2011 Thank you mate 3 hours spend for this Quote Link to comment https://forums.phpfreaks.com/topic/249988-how-to-loop/#findComment-1283124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.