Could someone suggest a rearrangement of my code
Posted: Mon Oct 23, 2006 9:28 am
I've been looking through old code and updating it as best as possible. One script I have come across is a voting system script but I've noticed that when you place a vote it never updates untill you refresh the page, or place a 2nd vote, but even then you 2nd vote doesn't update untill a 3rd vote is place or the screen is refreshed.
There is some more code that's HTML but you don't need to see that, I don't think.
I have suspicion it's where the mysql_query statements are placed.
Stephen,
Code: Select all
include_once("/var/www/html/php/db/logon.php");
mysql_connect($host, $user, $pass);
mysql_select_db("poll");
$qu = "SELECT * FROM votes";
$results = mysql_query($qu);
$i = 0;
$vote = $_REQUEST["proglan"];
if (isset($vote)) {
switch($vote) {
case "C++":
$cplus = mysql_result($results, $i, "cplus");
$newCplus = $cplus + 1;
$q = mysql_query("UPDATE votes SET cplus='$newCplus'");
break;
case "Java":
$java = mysql_result($results, $i, "java");
$newJava = $java + 1;
$q = mysql_query("UPDATE votes SET java='$newJava'");
break;
case "PHP":
$php = mysql_result($results, $i, "php");
$newPhp = $php + 1;
$q = mysql_query("UPDATE votes SET php='$newPhp'");
break;
default:
echo "How the hell?";
break;
}
}
$totalCplus = mysql_result($results, $i, "cplus");
$totalJava = mysql_result($results, $i, "java");
$totalPhp = mysql_result($results, $i, "php");
$foo = $totalCplus + $totalJava + $totalPhp;
$percCplus = $totalCplus / $foo * 100 * 2;
$percJava = $totalJava / $foo * 100 * 2;
$percPhp = $totalPhp / $foo * 100 * 2;
$percCplusOutput = $percCplus / 2;
$percJavaOutput = $percJava / 2;
$percPhpOutput = $percPhp / 2;I have suspicion it's where the mysql_query statements are placed.
Stephen,