Bewertungsfunktion

micronix

Mitglied
wie realisier ich solch eine bewertung das ab verschiedenen werten eine andere hand angezeigt wird aber der rest ausgefüllt wird mit blank händen ?
Hier das bild mit den dunklen bereichen...
http://img42.imageshack.us/img42/2886/handvc.png

Was noch mit drin sein soll sind die Hände

Ab 1 Vote = 1 Hand
Ab 13 Vote = 2 Hände
Ab 60 Vote = 3 Hände
Ab 300 Vote = 4 Hände
Ab 1000 Vote= 5 Hände

Hier eine kleine funktion die nicht geht
PHP:
<?php		
		public function populateRatingOnlyPositive($rating = 0, $rating_tot = 0)
			{
				$rating_total = $this->CFG['admin']['total_rating'];

				if($rating>$rating_total)
					$rating = $rating_total;
					
				if($rating_tot>$rating_total)
					$rating_tot = $rating_total;
				
				$extra_rating = $rating_tot;
				$bulet_star = $this->CFG['site']['url'].'images/content/small_thumb_up.png';
				$bulet_star_empty = $this->CFG['site']['url'].'images/video/blank_thumb_up.png';
				echo $rating_tot;
				
				
				for($i=1;$i<=$rating_tot;$i++)
						{
				if($rating_tot>1)
				{
				?>
					<acronym title='+ <?php echo $extra_rating;?> total'>
					<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $extra_rating;?> total' src='<?php echo $extra_rating;?>' /></acronym>		
				<?php
				}
				if($rating_tot>12)
				{
				?>
					<acronym title='+ <?php echo $rating_tot;?> total'>
					<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star;?>' /></acronym>		
				<?php
				}
				if($rating_tot>60)
				{
				?>
					<acronym title='+ <?php echo $rating_tot;?> total'>
					<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star;?>' /></acronym>		
				<?php
				}
				if($rating_tot>300)
				{
				?>
					<acronym title='+ <?php echo $rating_tot;?> total'>
					<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star;?>' /></acronym>		
				<?php
				}
				if($rating_tot>1000)
				{
				?>
					<acronym title='+ <?php echo $rating_tot;?> total'>
					<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star;?>' /></acronym>		
				<?php
				}
				?>

	<?php
						}
					
				for($i=$rating_tot;$i<$rating_total;$i++)
						{
							if($rating_tot>1)
							{
							?>
								<acronym title='+ <?php echo $extra_rating;?> total'>
								<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $extra_rating;?> total' src='<?php echo $bulet_star_empty;?>' /></acronym>		
							<?php
							}
							if($rating_tot>12)
							{
							?>
								<acronym title='+ <?php echo $rating_tot;?> total'>
								<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star_empty;?>' /></acronym>		
							<?php
							}
							if($rating_tot>60)
							{
							?>
								<acronym title='+ <?php echo $rating_tot;?> total'>
								<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star_empty;?>' /></acronym>		
							<?php
							}
							if($rating_tot>300)
							{
							?>
								<acronym title='+ <?php echo $rating_tot;?> total'>
								<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star_empty;?>' /></acronym>		
							<?php
							}
							if($rating_tot>1000)
							{
							?>
								<acronym title='+ <?php echo $rating_tot;?> total'>
								<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star_empty;?>' /></acronym>		
							<?php
							}
							else
							{
							?>
								<acronym title='+ <?php echo $rating_tot;?> total'>
								<img style='background:transparent;border:0;' class='thumb' alt='+ <?php echo $rating_tot;?> total' src='<?php echo $bulet_star_empty;?>' /></acronym>
							<?php
							}
						}
			}

Wäre über jede Hilfe sehr Dankbar

Liebe Grüße
Sascha
 
Zuletzt bearbeitet:
Wiso so kompliziert ?
PHP:
<?php
$votes = 1001; // wieviele votes

// anzahl der votes die benötigt werden
$vote1 = 1;  
$vote2 = 13;
$vote3 = 60;
$vote4 = 300;
$vote5 = 1000;

// wieviele daumen gibt es
$gesamtaumen = 5;

if($votes == 0)$daumen = 0;
if($votes>$vote1)$daumen = 1;
if($votes>$vote2)$daumen = 2;
if($votes>$vote3)$daumen = 3;
if($votes>$vote4)$daumen = 4;
if($votes>$vote5)$daumen = 5;

$diferez = $gesamtaumen - $daumen;

// ausgabe 
for($i=1;$i<=$diferez;$i++)
{
echo "A";
}
for($i=1;$i<=$daumen;$i++)
{
echo "B";
}
?>

mfg Spikaner
 
Die Bedigung deiner Schleife ist etwas seltsam.
Die Variable $rating_tot kann laut den If-Bedingungen über 1000 sein, somit würde die Schleife auch über 1000 mal durchgeführt werden, was dir auch genau so viele "Hände" ausgeben würde.

Ich würde vorschlagen, dass du es wie folgt machst:

PHP:
<?php		
for($i = 1; $i < 5; $i++) {
	if($rating_tot>1000)
	{
		// gib fuenf "volle" und keine "leere" Hand aus
	}
	elseif($rating_tot<=1000)
	{
		// gib vier "volle" und eine "leere" Hand aus
	}
	elseif($rating_tot<=300)
	{
		// gib drei "volle" und zwei "leere" Hände aus
	}
	elseif($rating_tot<=60)
	{
		// gib zwei "volle" und drei "leere" Hände aus
	}
	elseif($rating_tot<=12)
	{
		// gib eine "volle" und vier "leere" Hände aus
	}
	else
	{
		// gib keine "volle" und fuenf "leere" Hände aus
	}
}

Somit wäre auch die zweite Schleife unnötig.
Das ganze könnte man auch noch schöner machen, nur ist es vorerst so verständlicher. ;)


*edit*
Habe ich für die paar Zeilen gut eine viertel Stunde gebraucht? :confused:
Mensch, der Alkohol, ich muss ins Bett...haut rein. ;)
 
Wie ich befürchtet habe
Es geht leider nicht so einfach..
wenn z.b total 14 votes werden 2 hände angezeigt und der rest wird auch mit händen ausgefüllt die aber nicht sichtbar sind d.h blank also schwarz und im titel der hände sollte bei jeder hand die gesamten votes angezeigt werden also total votes + 14

Liebe Grüße
Sascha
 
Hasst du die Pic`s griffbereit.. dann mal her damit.. , weil mit A und B funktioniert das Script bei mir einwandfrei.
Und was meinst du mit + 14 ?

mfg Spikaner

P.S. was ist an meinen Ansatz falsch ?
 
wie soll ich in deiner schleife die blanken hände definieren ?
wenn ich nochmal die sache kopiere und den src änder wird alles doppelt angezeigt...

LG Sascha
 
Etwas umständlich aber ansich ersichtlich.. i hope

PHP:
<?php
$votes = 299;


$vote1 = 1;
$vote2 = 13;
$vote3 = 60;
$vote4 = 300;
$vote5 = 1000;
$gesamtaumen = 5;

if($votes == 0)$daumen = 0;
if($votes>=$vote1)$daumen = 1;
if($votes>=$vote2)$daumen = 2;
if($votes>=$vote3)$daumen = 3;
if($votes>=$vote4)$daumen = 4;
if($votes>=$vote5)$daumen = 5;

$diferez = $gesamtaumen - $daumen;

echo '<acronym title>+';
echo $votes;
echo "total";
echo '</acronym>';
for($i=1;$i<=$diferez;$i++)
{
echo '<img border="0" src="blank_thumb_up.png" width="16" height="22">';
}
for($i=1;$i<=$daumen;$i++)
{
echo '<img border="0" src="small_thumb_up.png" width="16" height="22">';
}
?>
mfg Spikaner
 
Zurück