/    Sign up×
Community /Pin to ProfileBookmark

help with little voting script thing

ok i have this page which processes a form where users vote on a bunch of different categories

[code=php]
<?
// this will put all the form elements into variables
$best_user=$_POST[“best_user”];
$funniest_user=$_POST[“funniest_user”];
$smartest_user=$_POST[“smartest_user”];
$best_icon=$_POST[“best_icon”];
$best_moderator=$_POST[“best_moderator”];
$best_admin=$_POST[“best_admin”];
$most_improved=$_POST[“most_improved”];
$best_new_user=$_POST[“best_new_user”];
$favorite_user=$_POST[“favorite_user”];
$most_helpful_user=$_POST[“most_helpful_user”];
//this will check to see if all form fields are fill out

if($best_user ==”” || $funniest_user ==”” || $smartest_user ==”” || $best_icon ==”” || $best_moderator ==”” || $best_admin ==”” || $most_improved ==”” || $best_new_user ==”” || $favorite_user ==”” || $most_helpful_user ==””)
{
echo”You must fill out all form fields.”;
}
else
{
$linkid= mysql_connect(“localhost”, “”, “”)or die(mysql_error());//connects
mysql_select_db(“ncs_awards”, $linkid) or die(mysql_error());//chooses database
$query = “INSERT INTO `awards` ( `ID` , `best_user` , `fun_user` , `smart_user` , `best_icon` , `best_mod` , `best_admin` , `most_improve` , `best_new` , `fav_user` , `most_help` ) ”
. ” VALUES ( ”, ‘$best_user’, ‘$funniest_user’, ‘$smartest_user’, ‘$best_icon’, ‘$best_moderator’, ‘$best_admin’, ‘$most_improved’, ‘$best_new_user’, ‘$favorite_user’, ‘$most_helpful_user’ );”
. ” “;
mysql_query($query) or die(mysql_error());//inserts into awards table
echo”Your votes have been recorded, have a nice day”;
}
?>
[/code]

That works fine in inserting all the votes into the db

Then I have this page which selects the vote from the database, this is what i need help with

[code=php]
<?
$linkid= mysql_connect(“localhost”, “root”, “”)or die(mysql_error());//connects
mysql_select_db(“ncs_awards”, $linkid) or die(mysql_error());//chooses database
$query=’SELECT * from awards’;//query to select everything from awards
$result= mysql_query($query);//performs query
while ($row = mysql_fetch_assoc($result))
{
$best_user = $row[‘best_user’];
$fun_user = $row[‘fun_user’];
$smart_user = $row[‘smart_user’];
$best_icon = $row[‘best_icon’];
$best_mod = $row[‘best_mod’];
$best_admin = $row[‘best_admin’];
$most_improve = $row[‘most_improve’];
$best_new = $row[‘best_new’];
$fav_user = $row[‘fav_user’];
$most_help = $row[‘most_help’];
echo'<b>’.$best_user.'</b><br>’;//echoes out the best user
}
?>
[/code]

For arguments sake lets say that 7 people voted Conor as the best user. Right now that will echo out conor 7 times like this

[b]
Conor
Conor
Conor
Conor
Conor
Conor
Conor
[/b]

I want it to display like this
[b]
Conor(7)
[/b]

Is this possible and if so can you point me in the right direction

Thanks,
Conor

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@GenixdeaeApr 18.2004 — i can't help you solve it but i can give you an idea of how it could be solved...

make a column called total. now when the user submits have it find out whos name has been enterd and add 1 to the column total.

that way would work if you set it up with who the voters can select to input. if the voters put in the names just make an if then statement checking to see if the user is in there, if so then update total, +1, else insert (columns) values (values)......

hope that helps ?
Copy linkTweet thisAlerts:
@ConorauthorApr 18.2004 — ^^ then there would have to be a colum like that for every person, and i cant predict who they will vote for.
Copy linkTweet thisAlerts:
@GenixdeaeApr 18.2004 — true, which like i said i couldnt solve it for you but i might be able to give you an idea of how to fix it ?
Copy linkTweet thisAlerts:
@ConorauthorApr 18.2004 — hmm i think what i would need to do would be to select and that someone count how many times each name exists.
×

Success!

Help @Conor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...