Avatar of mattibutt
mattibutt
Flag for United States of America asked on

showing multiple images for the poll output

hi
i have a poll which displays poll results using one image, i want to have couple of different images for result display
function print_results($poll_id)
{
	global $tapps_dir;
	global $tapps_pollbar_image_max_width;
 
	if (isset($tapps_pollbar_image_max_width))
		$barmaxwidth=$tapps_pollbar_image_max_width;
	else
		$barmaxwidth=128;
 
	$result = mysql_query("SELECT * FROM tapps_polls WHERE poll_id=$poll_id");
	$poll = mysql_fetch_object($result);
 
	if ($poll)
	{
		echo "<b>$poll->title</b><br>\n";
		echo "<br>\n";
		echo "$poll->description<br>\n";
		echo "<br>\n";
 
		$result = mysql_query("SELECT SUM(counter) AS sum_counter FROM tapps_votes WHERE poll_id=$poll_id");
		$o = mysql_fetch_object($result);
		$sum_counter = $o->sum_counter;
 
		$result = mysql_query("SELECT MAX(counter) AS max_counter FROM tapps_votes WHERE poll_id=$poll_id");
		$o = mysql_fetch_object($result);
		$max_counter = $o->max_counter;
 
		$result = mysql_query("SELECT option_text,counter FROM tapps_votes WHERE poll_id=$poll_id ORDER BY option_id");
 
		echo "<table cellpadding=0 cellspacing=4>\n";
 
		while ($row = mysql_fetch_object($result))
		{
			echo "<tr>\n";
			echo "<td>$row->option_text</td>\n";
			if ($row->counter > 0)
			{
				$p = (float)(100*$row->counter/$sum_counter);
				$w = (int)($barmaxwidth*$row->counter/$max_counter);
			}
			else
			{
				$p = 0;
				$w = 1;
			}
			$s = strip_tags($row->option_text);
			echo "<td><img src=\"".$tapps_dir."poll_bar.jpg\" height=15 width=$w alt=\"$s\"></td>\n";
			printf("<td>%.1f %% (%d)</td>\n", $p, $row->counter);
			echo "</tr>\n";
		}

Open in new window

PHPScripting Languages

Avatar of undefined
Last Comment
Jomjai

8/22/2022 - Mon
Ray Paseur

It should not be too hard to do this.  What other images would you like to show?  What variables would your programming identify that would cause it to display different images?
mattibutt

ASKER
hi ray
i hope you are well,  for now i just want to add few more images are you asking about name of the images?
say if poll has more options like 3 or 4 i would like to have different images for each poll result
Ray Paseur

Thanks.  I would think you might modify the function above to add the "extra image" logic.  It looks like the code is putting an image into a table, and calculating the width of the image.  Perhaps somewhere in that area you could add the code to present another image.

In an unrelated matter, it looks like this code is doing 4 queries against one data base table.  A more efficient approach might be to combine the queries.  Just a thought.

;-)

~Ray
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
mattibutt

ASKER
hi ray
how do i write the logic for another image shed some light if u can
Ray Paseur

If you can tell me what circumstances would exist that would signal your program to use another image, we can put in some "if" statements to test for these circumstances.  We could also add a field to the function definition to pass an image identifier into the function, and then we could use the image identifier to get the image file name into the generated HTML.  Does that make sense? ~Ray
mattibutt

ASKER
hi ray
the circumstances for displaying more then image would be if the row which is option text greater then one
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mattibutt

ASKER
this is how its shown in the browser, if i can display each option box with different image that would be great
<table cellpadding=0 cellspacing=4>
<tr>
<td>option 1</td>
<td><img src="poll_bar.jpg" height=55 width=128 alt="option 1"></td>
<td>44.4 % </td>
</tr>
<tr>
<td>option 2</td>
<td><img src="poll_bar.jpg" height=55 width=96 alt="option 2"></td>
<td>33.3 % </td>
</tr>
<tr>
<td>option 3</td>
<td><img src="poll_bar.jpg" height=55 width=64 alt="option 3"></td>
<td>22.2 % </td>
</tr>
</table>
mattibutt

ASKER
maybe i have not been able to explain to you properly
mattibutt

ASKER
i have added one more image but its showing it twice i dont understand what to change for each option text box will show different image
                  echo "<td><img src=\"".$tapps_dir."image5.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
                  printf("<td>%.1f %% </td>\n", $p, $row->counter);
                  echo "<td><img src=\"".$tapps_dir."poll_bar.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
                  printf("<td>%.1f %% </td>\n", $p, $row->counter);
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

Can you show me a link to the page that is showing the image twice?  If I look at the generated HTML I amy be able to offer a suggestion.  Thanks
mattibutt

ASKER
here is the generated html
What is your favourite game<br> 
<br> 
<table cellpadding=0 cellspacing=4> 
<tr> 
<td>Assasin Creed</td> 
<td><img src="image5.jpg" height=55 width=128 alt="Assasin Creed"></td> 
<td>44.4 % </td> 
<td><img src="poll_bar.jpg" height=55 width=128 alt="Assasin Creed"></td> 
<td>44.4 % </td> 
</tr> 
<tr> 
<td>American Chopper</td> 
<td><img src="image5.jpg" height=55 width=96 alt="American Chopper"></td> 
<td>33.3 % </td> 
<td><img src="poll_bar.jpg" height=55 width=96 alt="American Chopper"></td> 
<td>33.3 % </td> 
</tr> 
<tr> 
<td>t</td> 
<td><img src="image5.jpg" height=55 width=64 alt="t"></td> 
<td>22.2 % </td> 
<td><img src="poll_bar.jpg" height=55 width=64 alt="t"></td> 
<td>22.2 % </td> 
</tr> 
</table> 
<br> 
<BR> 
<BR> 
</CENTER> 
</BODY> 
</HTML> 
</div> 
</td> 

Open in new window

mattibutt

ASKER
right now all the results are assigned to this       $s = strip_tags($row->option_text); i think if i can break this down in for example row 1 then image1 and row2 then image2 etc
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ray Paseur

Do you mean multiple rows for each instance?  See if the code snippet is like what you're looking for.
MAYBE CHANGE THIS
 
<tr> 
<td>Assasin Creed</td> 
<td><img src="image5.jpg" height=55 width=128 alt="Assasin Creed"></td> 
<td>44.4 % </td> 
<td><img src="poll_bar.jpg" height=55 width=128 alt="Assasin Creed"></td> 
<td>44.4 % </td> 
</tr> 
 
INTO THIS
 
<tr> 
<td>Assasin Creed</td> 
<td><img src="image5.jpg" height=55 width=128 alt="Assasin Creed"></td> 
<td>44.4 % </td>
</tr>
 
<tr>
<td> </td> 
<td><img src="poll_bar.jpg" height=55 width=128 alt="Assasin Creed"></td> 
<td>44.4 % </td> 
</tr> 

Open in new window

mattibutt

ASKER
no sorry ray if i confused you i still need single instance per row but image for each row should be different
mattibutt

ASKER
the results happened when i tried to add another image but it didnt go according to the plan
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Ray Paseur

OK, so one row for each instance.  Got it.  Where will the images be found?  How will we know which image should go with each row?
mattibutt

ASKER
some way to break down this $s = strip_tags($row->option_text); for instance largest option_text will have image1 and then if its smaller then image2
            $s = strip_tags($row->option_text);
                  echo "<td><img src=\"".$tapps_dir."image5.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
            printf("<td>%.1f %% </td>\n", $p, $row->counter);

Ray Paseur

I'm still not getting it.  "largest option_text" - what does"largest" mean in this context?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mattibutt

ASKER
hi ray
sorry once again for confusing you
    printf("<td>%.1f %% </td>\n", $p, $row->counter); the counter has value of poll results in percentage (42.9 %)  so i am thinking some if statement where largest   printf("<td>%.1f %% </td>\n", $p, $row->counter); will have different image
mattibutt

ASKER
can i do this in php like
original code
                  $s = strip_tags($row->option_text);
                  echo "<td><img src=\"".$tapps_dir."image5.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
            printf("<td>%.1f %% </td>\n", $p, $row->counter);
desire modification
            $s = strip_tags($row(here someway i can enter row number)->option_text);
                  echo "<td><img src=\"".$tapps_dir."different.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
            printf("<td>%.1f %% </td>\n", $p, $row->counter);
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mattibutt

ASKER
thanks buddy
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Ray Paseur

You're welcome, and thanks for the points!  Best, ~Ray
Jomjai

Test Post Message