Hello,

I created a (very) simple class for a polling system. I only developed it to a certain stage (took me a few hours).

This was how you used it:

<?php

$poll = new easyPoll("poll_name");
$poll->PrintVotingPanel();

?>

and if you wanted to show all the results of all polls

<?php

$poll = new easyPoll();
$pollNames = $poll->GetAllPolls();

for ($i=0; $i<count($pollNames); $i++){
$poll = new easyPoll($pollNames[$i]);
$poll->PrintResults();
echo "<br><br>";
}

?>


Here is my table structure, and a few of my SQL statements.


// for the voting panel

$sql = "SELECT * FROM tblPoll, tblPollItems
WHERE pollName = '".$this->PollName."'
AND pollID = pollID_FK
ORDER BY itemOrder";

// getting the actual amounts for displaying data

$sql = "SELECT pollQuestion, itemText, count(voteID) as numVotes
FROM tblPoll, tblPollItems as t1 LEFT JOIN tblVotes as t2
ON t1.itemID = t2.itemID_FK
WHERE pollID = pollID_FK
AND pollName = '".$this->PollName."'
GROUP BY itemID
ORDER BY itemOrder";

--
-- Table structure for table 'tblPoll'
--

CREATE TABLE tblPoll (
pollID bigint(20) NOT NULL auto_increment,
pollName tinytext NOT NULL,
pollQuestion tinytext NOT NULL,
startDate date NOT NULL default '0000-00-00',
endDate date NOT NULL default '0000-00-00',
PRIMARY KEY (pollID)
) TYPE=MyISAM;

--
-- Table structure for table 'tblPollItems'
--

CREATE TABLE tblPollItems (
itemID bigint(20) NOT NULL auto_increment,
pollID_FK bigint(20) NOT NULL default '0',
itemText tinytext NOT NULL,
itemOrder tinyint(4) NOT NULL default '0',
PRIMARY KEY (itemID)
) TYPE=MyISAM;

--
-- Table structure for table 'tblVotes'
--

CREATE TABLE tblVotes (
voteID bigint(20) NOT NULL auto_increment,
itemID_FK bigint(20) NOT NULL default '0',
voteTime bigint(20) NOT NULL default '0',
voterIP tinytext,
PRIMARY KEY (voteID)
) TYPE=MyISAM;


Hope this helps....

BTW - if you want, i can give you all the source code for the class, but currently it is not very customizable - lots of things are hard-coded.

Adam


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to