Want to make a poll, but need to know where to start.<

liunx

Guest
OK, I'm want to write my first php script. I have a basic knowledge of php. What I want to do is make a poll, that I can change every week to two weeks. It's going to have 5 options, and the results after you vote need to show up on a different page. I know I have to make the action of the poll page.php. I'm pretty sure I have to use mysql, which i'm not too familiar with. I guess I have to have each vote stored in a db for each option voted, and then called on the page with the results.

An example of something I'm looking for is here (<!-- m --><a class="postlink" href="http://pub.alxnet.com/poll?id=2387292&q=view">http://pub.alxnet.com/poll?id=2387292&q=view</a><!-- m -->)

Even with the bars.

So can somebody give me some advice on where to start, I'm not asking for the whole code. Maybe just parts of it or functions that I could use. And how to set up the database.Why not Download one that is already made, and play with it, instead of starting from scratch?

<!-- m --><a class="postlink" href="http://www.hotscripts.com/PHP/Scripts_and_Programs/Polls_and_Voting/index.html">http://www.hotscripts.com/PHP/Scripts_a ... index.html</a><!-- m -->

Always easier to learn from others mistakes.I'd like to right my own script for practice.Originally posted by hockyfan641
I'd like to right my own script for practice.

and i agree with you.

i would actually recommend using a text file for this, its much easier to edit;)

take a look at this:


$log="data.txt"; //counter log file. a flat text file.

$open=fopen($log,'r+'); //opens the file.
$counter=fread($open,filesize($log)); //reads the file
fclose($open);
$counter++; // adds 1 to the counter file.
$write=fopen($log,'w'); //opens the file for writing.
fputs($write,$counter); //writes to the file.
fclose($write); //closes the file.

this is a simple example of opening a file and incrementing the contents by one.

to decide which file to open, you can simply do an if() statement to check through all of the options, and youve just got to echo the results:

echo $counter;
echo $counter2;
echo $counter3;
//etc etc etc


but thats just my opinion, there probably a better way to do it

;)Originally posted by hockyfan641
I'd like to right my own script for practice.

Okies. In your original message you were asking for help on a few functions, and how to set up a database. So what is the difference from someone else helping you on this board, and you adapting a GPL script to learn from?

Makes no difference to me really, but I tended to learn more from seeing why others made the choices that they did rather than me starting out making choices.Check out this tutorial I posted in another threat.

<!-- m --><a class="postlink" href="http://www.devshed.com/Server_Side/PHP/PHPDemocracy/page1.html">http://www.devshed.com/Server_Side/PHP/ ... page1.html</a><!-- m -->

Its good for a reference if you want to write your own.ahh...good tutorial. I'll check it out. Thanks.
 
Back
Top