Hi there, I'm creating a PHP/XML-based voting system. There are 24 options for a user to vote from, and ideally I'd like the user to see a picture of each person they vote for. So far, I've managed to list all the names of people up for voting from a "poll.xml" file in my "poll.php" file which is what web users will go to in order to vote. It also correctly updates the tally in the XML file when a person is voted for. The only thing that doesn't work now is trying to get an image to display next to each person's name...any ideas? Or would I have to learn XSLT to do this? (I have none currently, just a plain XML file and PHP file).
Thanks for your time! Appropriate sections of each file are below :)
POLL.PHP
[PHP]function printVotingForm ($pid) {
// get these variables in this scope
global $polls, $header_file, $footer_file;
// include header file
include($header _file);
// print poll title and form
echo "<h3 style=\"text-align: center\">" . $polls->poll[$pid]['title'] . "</h3>\n";
echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\" >\n";
echo "<fieldset> \n";
echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />\n";
echo "<ul style=\"list-style-type: none\">\n";
// count number of answers
$no_answers = count($polls->poll[$pid]->answers->answer);
// print each answer as a checkbox
if ($polls->poll[$pid]->multipleanswer s == "yes") {
for ($i = 0; $i < $no_answers; $i++) {
echo "<li><input type=\"checkbox \" name=\"vote[]\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . "</li>\n";
}
}
// print each answer as a radio button
else {
for ($i = 0; $i < $no_answers; $i++) {
echo "<li><input type=\"radio\" name=\"vote\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . "</li>\n";
}
}
echo "</ul>\n";
echo "<p style=\"text-align: center\"><input type=\"submit\" value=\"Vote\" /> or <a href=\"" . $_SERVER['PHP_SELF'] . "?pid=$pid& view_results=1\ ">View Results</a></p>\n";
echo "</fieldset>\n";
echo "</form>\n";
// include footer file
include($footer _file);
}
}
[/PHP]
POLL.XML
[PHP]<?xml version="1.0"?>
<polls>
<poll title="Who do you think should win the vote this year?">
<answers>
<answer>
<name>Michael </name>
<tally>0</tally>
<image>src_here .gif</image>
</answer>
<answer>
<name>Sophie</name>
<tally>0</tally>
</answer>
</answers>
</poll>
</polls>[/PHP]
Thanks for your time! Appropriate sections of each file are below :)
POLL.PHP
[PHP]function printVotingForm ($pid) {
// get these variables in this scope
global $polls, $header_file, $footer_file;
// include header file
include($header _file);
// print poll title and form
echo "<h3 style=\"text-align: center\">" . $polls->poll[$pid]['title'] . "</h3>\n";
echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\" >\n";
echo "<fieldset> \n";
echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />\n";
echo "<ul style=\"list-style-type: none\">\n";
// count number of answers
$no_answers = count($polls->poll[$pid]->answers->answer);
// print each answer as a checkbox
if ($polls->poll[$pid]->multipleanswer s == "yes") {
for ($i = 0; $i < $no_answers; $i++) {
echo "<li><input type=\"checkbox \" name=\"vote[]\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . "</li>\n";
}
}
// print each answer as a radio button
else {
for ($i = 0; $i < $no_answers; $i++) {
echo "<li><input type=\"radio\" name=\"vote\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . "</li>\n";
}
}
echo "</ul>\n";
echo "<p style=\"text-align: center\"><input type=\"submit\" value=\"Vote\" /> or <a href=\"" . $_SERVER['PHP_SELF'] . "?pid=$pid& view_results=1\ ">View Results</a></p>\n";
echo "</fieldset>\n";
echo "</form>\n";
// include footer file
include($footer _file);
}
}
[/PHP]
POLL.XML
[PHP]<?xml version="1.0"?>
<polls>
<poll title="Who do you think should win the vote this year?">
<answers>
<answer>
<name>Michael </name>
<tally>0</tally>
<image>src_here .gif</image>
</answer>
<answer>
<name>Sophie</name>
<tally>0</tally>
</answer>
</answers>
</poll>
</polls>[/PHP]
Comment