Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Online Voting 1

Status
Not open for further replies.

overyde

Programmer
Joined
May 27, 2003
Messages
226
Location
ZA
Hi,
I have been attempting to create a site in php and mysql to cast online votes. Problem is unlike other voting polls that have 1 poll on the page, I have to have 5 polls related to 1 topic and 1 submit button all linked to the relative user in a db!!! What it actually is a market research site. The client is listed on the site (say it's a bar) then the user votes on the service, quality, affordability, management and ambience of the establishment (rated as excellent, good, average and bad). I have created a basic script which is linked to a voting form. When the user presses submit, the relative choice increments by 1(say the service is average-so average would increase by 1) but I cannot get it to write to the dbase. Does ANYONE have ANY ideas?!?!?!?

Reality is built on a foundation of dreams.
 
I thought I answered your previous post, but obviously not.

Here's what I think you should do:

1. You have a set of radio buttons for the five service questions. Each radio button has a specific value.

2. You db records is:
Code:
user * servicea * serviceb * servicec * serviced *
**************************************************
wazza*     1    *    5     *     3    *    2     *
**************************************************

3. You know the user voted on and the values.

In your previous post you read the current value of the record in. You don't need to do that. There's no need to compare anything, just update the record using the values posted:

Code:
# loop through the POSTed vars
foreach($_POST as $key => $value){
   # check if it's a 'service' variable
   if(strstr('service',$key)){
      # add to the SQL updates
      # add the number internally that was voted
      $fieldClause[]= "SET $key = $key+$value";
   }
}
# assemble SQL
$fields = implode(', ',$fieldClause);
$SQL = "UPDATE place ".$fields." WHERE user='wazza'";

If you just want to add 1 replace $value in the fieldClause array with 1.
 
Thanks DRJ478
Will try this out as soon as I can. I'm currently restructuring my dbase so as it can do all the work instead of typing in all the code and working it out on the programming side. I believe that in the long run, making huge tables would end up being a huge task. I instead have started making several smaller relational tables. Surely this would be better? Are there more cons than pros to doing it this way?

sleipnir214
It just wasn't writing to the dbase. When you pressed submit-it looked like it had but it didn't!!
I think DRJ478 has helped.
Thanks!

Reality is built on a foundation of dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top