Jump to content

how to loop?


ctcp

Recommended Posts

$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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.