mattibutt
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
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";
}
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?
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
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
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
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
ASKER
hi ray
how do i write the logic for another image shed some light if u can
how do i write the logic for another image shed some light if u can
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
ASKER
hi ray
the circumstances for displaying more then image would be if the row which is option text greater then one
the circumstances for displaying more then image would be if the row which is option text greater then one
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>
<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>
ASKER
maybe i have not been able to explain to you properly
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_b ar.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
printf("<td>%.1f %% </td>\n", $p, $row->counter);
echo "<td><img src=\"".$tapps_dir."image5
printf("<td>%.1f %% </td>\n", $p, $row->counter);
echo "<td><img src=\"".$tapps_dir."poll_b
printf("<td>%.1f %% </td>\n", $p, $row->counter);
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
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>
ASKER
right now all the results are assigned to this $s = strip_tags($row->option_te xt); i think if i can break this down in for example row 1 then image1 and row2 then image2 etc
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>
ASKER
no sorry ray if i confused you i still need single instance per row but image for each row should be different
ASKER
the results happened when i tried to add another image but it didnt go according to the plan
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?
ASKER
some way to break down this $s = strip_tags($row->option_te xt); for instance largest option_text will have image1 and then if its smaller then image2
$s = strip_tags($row->option_te xt);
echo "<td><img src=\"".$tapps_dir."image5 .jpg\" height=55 width=$w alt=\"$s\"></td>\n";
printf("<td>%.1f %% </td>\n", $p, $row->counter);
$s = strip_tags($row->option_te
echo "<td><img src=\"".$tapps_dir."image5
printf("<td>%.1f %% </td>\n", $p, $row->counter);
I'm still not getting it. "largest option_text" - what does"largest" mean in this context?
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
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
ASKER
can i do this in php like
original code
$s = strip_tags($row->option_te xt);
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."differ ent.jpg\" height=55 width=$w alt=\"$s\"></td>\n";
printf("<td>%.1f %% </td>\n", $p, $row->counter);
original code
$s = strip_tags($row->option_te
echo "<td><img src=\"".$tapps_dir."image5
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."differ
printf("<td>%.1f %% </td>\n", $p, $row->counter);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks buddy
You're welcome, and thanks for the points! Best, ~Ray
Test Post Message