Results 1 to 8 of 8

Thread: working on a poll (NEED HELP)

  1. #1
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default working on a poll (NEED HELP)

    im VERY new with php and i have been working on a site... i want to add a poll but i am stuck!

    Here is topgames.php

    PHP Code:
    <?php
    mysql_connect
    ("localhost""(removed username)""(pass removed for security reasons)") or die(mysql_error()); 
    mysql_select_db("demonic_vote") or die(mysql_error());

    $ip "$HTTP_SERVER_VARS[REMOTE_ADDR]";
    $Awesome=mysql_query("select * from results where Awesome='$Awesome'");
    $Ok=mysql_query("select * from results where Ok='$Ok'");
    $Terrible=mysql_query("select * from results where Terrible='$Terrible'");
    $dupe1 mysql_query("select * from results where ip='$ip'");

        if (
    $dupe1 0) {
    ?>
    <font color="00ff00"><center>Results:<br>
    <h4>Awesome Votes: <?php print($Awesome?><br>
    Ok Votes: <?php print($Ok?><br>
    Terrible Votes: <?php print($Terrible?></h4></center></font>

    <?php
        
    }
    else

    ?>
    <center><form action="vote.php" method="post">
    <font color="#00ff00">Vote that this game is</font> <font color="#FFFF00">Awesome:</font> <input type="radio" name="Vote" value="Awesome"><br>
    <font color="#00ff00">Vote that this game is</font> <font color="#FFFF00">Ok:</font> <input type="radio" name="Vote" value="Ok"><br>
    <font color="#00ff00">Vote that this game is</font> <font color="#FFFF00">Terrible</font>: <input type="radio" name="Vote" value="Terrible"><p>
    <input type="submit" value="Vote" name="Vote">
    </form></center>
    <?php
    }
    ?>
    Then this is vote.php

    PHP Code:
    <?php
    mysql_connect
    ("localhost""(removed username)""(pass removed)") or die(mysql_error()); 
    mysql_select_db("demonic_vote") or die(mysql_error());

    $Awesome=mysql_query("select * from results where Awesome='$Awesome'");
    $Ok=mysql_query("select * from results where Ok='$Ok'");
    $Terrible=mysql_query("select * from results where Terrible='$Terrible'");

    if (isset(
    $_POST['submit'])) { 
    if (
    $_POST['Awesome'])
    {
    mysql_query("UPDATE * results SET Awesome=Awesome+1 WHERE Awesome='$Awesome'"
    or die(
    mysql_error());
    echo 
    "Voted <a href=\"topgames.php\">Go to topgames</a>";
    exit;
    }
    elseif (
    $_POST['OK'])
    {
    mysql_query("UPDATE * results SET Ok=Ok+1 WHERE Ok='$Ok'"
    or die(
    mysql_error());
    echo 
    "Voted <a href=\"topgames.php\">Go to topgames</a>";
    exit;
    }
    elseif (
    $_POST['Terrible'])
    {
    mysql_query("UPDATE * results SET Terrible=Ok+1 WHERE Terrible='$Terrible'"
    or die(
    mysql_error());
    echo 
    "Voted <a href=\"topgames.php\">Go to topgames</a>";
    exit;
    }
    }
    ?>
    Something happened... <a href="topgames.php">Go back</a>
    Lastly the MYSQL table

    Code:
    CREATE TABLE `results` (
      `id` int(11) NOT NULL auto_increment,
      `ip` int(20) NOT NULL default '1.1.1.1',
      `Awesome` int(30) NOT NULL default '0',
      `Ok` int(30) NOT NULL default '0',
      `Terrible` int(30) NOT NULL default '0',
      UNIQUE KEY `id` (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=1 ;
    if any of you smart coders out there could help it would be great... you see i tried writing this code with logic, not syntax, and i completely messed up

    again PLEASE help... this is one of the first things i coded without a wizard and its difficult it is
    Last edited by Demonicman; 02-26-2007 at 10:49 PM.

  2. #2
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    wow no suggestions? im extremely dissapointed with all you smart people out there XD

    i also forgot to mention that you can see this code in use at www.kalrith.com

  3. #3
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here's a poll script that I made awhile back:

    Code:
    #updated 7/14/06
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html><head>
      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Render</title></head>
    
    <body style="background-color: rgb(0, 0, 0); background-image: url(bg.gif); color: rgb(255, 255, 255);" alink="#ffffff" link="#ffcc66" vlink="#cc6600">
    
    <?php
    
    
    function percent($value, $total)
    {
    	return round($value * 100.0 / $total, 2);
    }
    
    $vote = $_REQUEST['vote'];
    
    include('private/db_connect.inc');
    
    if (strlen($vote) != 0)
    {
    	$query1 = "UPDATE votes SET votecount = votecount + 1 WHERE songname = '$vote'";
    	$result1 = @mysql_query($query1);
    	if (!$result1)
    	{
    		echo 'MySql error.';
    	}
    }
    
    $query2 = "SELECT * FROM votes ORDER BY 'songname' ASC";
    $result2 = @mysql_query($query2);
    
    if ($query2)
    {
    	$fudge_factor = 0;
    	$votes = mysql_fetch_array($result2, MYSQL_NUM);
    	$broken = $votes[1] + $fudge_factor;
    	$votes = mysql_fetch_array($result2, MYSQL_NUM);
    	$someday = $votes[1] + $fudge_factor;
    	$votes = mysql_fetch_array($result2, MYSQL_NUM);
    	$stranded = $votes[1] + $fudge_factor;
    	$votes = mysql_fetch_array($result2, MYSQL_NUM);
    	$wasted = $votes[1] + $fudge_factor;
    	$votes = mysql_fetch_array($result2, MYSQL_NUM);
    	$youare = $votes[1] + $fudge_factor;
    	$totalvotes = $broken + $someday + $stranded + $wasted + $youare;
    	$brokenPercent = percent($broken, $totalvotes);
    	$somedayPercent = percent($someday, $totalvotes);
    	$strandedPercent = percent($stranded, $totalvotes);
    	$wastedPercent = percent($wasted, $totalvotes);
    	$youarePercent = percent($youare, $totalvotes);
    	echo "Broken Hearted Man: $brokenPercent&#37;<br>";
    	echo "Someday Go Away: $somedayPercent%<br>";
    	echo "Stranded: $strandedPercent%<br>";
    	echo "Wasted Life: $wastedPercent%<br>";
    	echo "You Are: $youarePercent%";
    }
    else
    {
    	echo 'MySql error.';
    }
    
    ?><br>
    <script type="text/javascript"><!--
    google_ad_client = "pub-3724700937860885";
    google_ad_width = 234;
    google_ad_height = 60;
    google_ad_format = "234x60_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "666666";
    google_color_bg = "000000";
    google_color_link = "000000";
    google_color_text = "FFFFFF";
    google_color_url = "FFCC66";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </body></html>
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  4. #4
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    thanks but a sql would be nice if you please

  5. #5
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    SQL gives me headaches. so heres a flat file DB poll code. works perfect, i made it specifically for you.
    PHP Code:
    <?php
    $save 
    "save.txt";
    $file file_get_contents($save); if(!$file) {die("File Not Found");};
    $array explode("|",$file);

    if(isset(
    $_POST['choice'])) {

    $cho $_POST['choice'];
    $array[$cho]++;
    $data implode("|",$array);
    $handle fopen($save,"w+");
    fwrite($handle,$data);
    fclose($handle);

    echo 
    "You picked choice number"$cho ."\r\n<br>";
    echo 
    "Click <a href=\"?look\">Here</a> to View The Results.";

    } elseif (isset(
    $_GET['look'])) { ?>

    Choice One: <?php echo $array['0']; ?><br>
    Choice Two: <?php echo $array['1']; ?><br>
    Choice Three: <?php echo $array['2']; ?><br>

    <?php /* Repeat above and below For Each Choice you want... */ } else { ?>
    <form action="poll.php" method="post">

    Choice One: <input type="radio" name="choice" value="0"><br>
    Choice Two: <input type="radio" name="choice" value="1"><br>
    Choice Three: <input type="radio" name="choice" value="2"><br>

    <input type="submit" value="Vote" name="Vote"></form>
    <?php };
    /* Contents of "save.txt"

    0|0|0

    have a zero for each choice you want, and a | in between each zero.
    in the "look" section, repeat

    */
    ?>
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  6. #6
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    81
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I'm pretty new to PHP too. I needed a poll on my site and i ran into this script:

    http://www.cj-design.com/products/fr.../cjdynamicpoll

    It's free and pretty easy to set up and maintain.

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Another one that I can think of (which uses AJAX, PHP, and MySQL) is on DHTMLgoodies.com. Here's the demo:
    http://dhtmlgoodies.com/scripts/ajax...ax-poller.html

    And info about how to install it is here:
    http://dhtmlgoodies.com/index.html?w...pt=ajax-poller

    Hope this helps.
    Last edited by thetestingsite; 02-28-2007 at 01:56 AM.

  8. #8
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    wow thanks for all the help guys! i should be able to create a really decent poll now! thanks all around

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •