Hi, my page randomly generates an image (painting). the user then has the option to rate the painting on a scale of 1 to 10. However i need two things:
1.
I want to change the radio buttons to images. I currently have 10 radio buttons with a RATE button beside it. When a user clicks a radio button, they then have to click the RATE buttin to submit the vote. I want an image (10 images) there instead and when the user clicks on the image it automatically submits the rating.
The second thing i need is an image swap on each of the 10 images. The images are stored in a folder called images/rate & the are called 1.GIF (and the rollover image is called 1c.GIF)
Here is my current code (with the radio buttons):
PLEASE PLEASE PLEASE can someone help me achieve the above tasks PLEASE…
[code=php]<?php
session_start();
//rate.php
// make connection to database
$dbh = mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“test”) or die(mysql_error());
if (array_key_exists(‘id_value’, $_POST))
{
//Get value from radio button
$id_to_rate = ereg_replace(“[^A-Za-z0-9]”, “”, $_POST[‘id_value’]);
$new_rating = $_REQUEST[‘rating’];
//Get values of results according to ID
$query = “SELECT total, average_score, votes FROM accounts where id =’$id_to_rate'”; // select 1 random record from accounts
$results = mysql_query($query);
$scoreslist = mysql_fetch_array($results);
//Retrieve current values from database
$total = $scoreslist[‘total’];
$average_score = $scoreslist[‘average_score’];
$votes = $scoreslist[‘votes’];
//Calculate new values
$new_votes = $votes + 1;
$new_total = $total + $new_rating;
$new_average= $new_total / $new_votes;
$new_average= number_format($new_average, 2);
//session_start();
$_SESSION[‘previousid’] = $id_to_rate;
$updatequery = “Update accounts set total = $new_total, average_score = $new_average, votes = $new_votes where id = $id_to_rate”;
if (!mysql_query($updatequery, $dbh))
{
die(‘Error: ‘.mysql_error());
}
}
?>
[code=html]<!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 3.2 Final//EN’>
<html>
<head>
<title>Rate Painting</title>
<meta http-equiv=’Content-Type’ content=’text/html; charset=utf-8′>
<link rel=stylesheet href=stylesheet.css type=text/css>
</head>
<body>
<div align=center>
<table width=”760″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”145″><a href=”index.php” target=”_self”><img src=”Images/lt.gif” width=”145″ height=”58″ border=”0″></a></td>
<td width=”145″><a href=”index.php” target=”_self”><img src=”Images/rt.gif” width=”145″ height=”58″ border=”0″></a></td>
<td align=”right” width=”470″> <table width=465 border=0 cellspacing=0 cellpadding=0 class=”table_header”>
<tr>
<td width=2><img src=Images/status_bar_l.gif width=2 height=27></td>
<td align=right background=Images/status_bar_background.gif><a href=”sign.php” target=”_self” class=”linksHeader”>Sign
In</a></td>
<td width=10 align=right background=Images/status_bar_background.gif><img src=Images/arrow.gif width=10 height=27 hspace=5></td>
<td width=3 align=right><img src=Images/status_bar_background.gif width=3 height=27></td>
<td width=2><img src=Images/status_bar_r.gif width=2 height=27></td>
</tr>
</table></td>
</tr>
<tr>
<td height=”58″><a href=”index.php” target=”_self”><img src=”Images/lb.gif” width=”145″ height=”58″ border=”0″></a></td>
<td colspan=”2″></td>
</tr>
</table>
<!–section under navigation–>
<!–<table width=760 border=0 cellspacing=0 cellpadding=0>
<tr>
<td height=”12″> </td>
</tr>
</table>–>
<?php
$sql = “SELECT * FROM accounts ORDER BY RAND() LIMIT 1”; // select 1 random record from accounts
$result = mysql_query($sql);
$nrows = mysql_num_rows($result);
if ($nrows != 0) {
$list = mysql_fetch_array($result);
$id_to_rate = $list[‘id’];
$current_score = $list[‘average_score’];
$current_votes = $list[‘votes’];
?>
[code=html] <table width=760 border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=259 height=”520″ vAlign=top bgcolor=”#FFFFFF”>
<?php
if (isset($_SESSION[‘previousid’]))
{//print “first”;
$id = $_SESSION[‘previousid’];
$sqllastrating = “SELECT average_score, votes FROM accounts where id= $id”; // select 1 random record from accounts
$previousresult = mysql_query($sqllastrating);
$previouslist = mysql_fetch_array($previousresult);
$votedaverage = $previouslist[‘average_score’];
$votedvotes = $previouslist[‘votes’];
session_destroy();
?>
[code=html]<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td height=”117″ colspan=”2″ class=”rate_top”><table width=”100%” height=”106″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”85%”> </td>
<td width=”15%”> </td>
</tr>
<tr>
<td height=”54″ class=”average”>
<?php print $votedaverage;?>
</td>
<!– average –>
<td> </td>
</tr>
</table></td>
</tr
><tr>
<td width=”33%” height=”62″ class=”rate_bottom_left”> </td>
<td width=”67%” height=”62″ class=”rate_bottom_right”><table width=”100%” height=”78″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”49%” height=”52″ class=”votes”>
<?php print $votedvotes;?>
</td>
<!– votes –>
<td width=”51%”> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
<tr><td colspan=”3″ height=”100″><table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”54%”><img src=”Images/rate/you_voted.jpg” width=”130″ height=”40″></td>
<td width=”46%” class=”you_voted”><?php print $new_rating; ?></td>
</tr>
</table></td></tr>
</table>
<table width=”240″ border=”0″ cellspacing=”0″ cellpadding=”0″ align=”center”>
<tr>
<td width=”140″><a href=”rate_colour.php” target=”_self”><img src=”Images/rate/colour.jpg” width=”130″ height=”75″ border=”0″></a></td>
<td width=”105″> </td>
</tr>
<tr>
<td><a href=”rate_black_and_white.php” target=”_self”><img src=”Images/rate/black_and_white.jpg” width=”130″ height=”75″ border=”0″></a></td>
<td> </td>
</tr>
<tr>
<td><img src=”Images/rate/both.jpg” width=”130″ height=”75″></td>
<td><img src=”Images/rate/tick.jpg” width=”100″ height=”70″></td>
</tr>
</table>
<?php
}
else{
?>
[code=html]<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td height=”145″ colspan=”2″ class=”rate_me”> </td>
</tr>
</table>
<?php
}
?>
[code=html]<br></td>
<td width=501 vAlign=top bgcolor=”#FFFFFF”>
<table align=center cellpadding=0 cellspacing=0 border=0>
<form METHOD=”post” NAME=”rating” ACTION=”<?php echo $_SERVER[‘PHP_SELF’];?>”>
<tr>
<td>1<input TYPE=”radio” class=“ratebutton” name=”rating” value=”1″ /></td>
<td>2<input TYPE=”radio” class=“ratebutton” name=”rating” value=”2″ /></td>
<td>3<input TYPE=”radio” class=“ratebutton” name=”rating” value=”3″ /></td>
<td>4<input TYPE=”radio” class=“ratebutton” name=”rating” value=”4″ /></td>
<td>5<input TYPE=”radio” class=“ratebutton” name=”rating” value=”5″ /></td>
<td>6<input TYPE=”radio” class=“ratebutton” name=”rating” value=”6″ /></td>
<td>7<input TYPE=”radio” class=“ratebutton” name=”rating” value=”7″ /></td>
<td>8<input TYPE=”radio” class=“ratebutton” name=”rating” value=”8″ /></td>
<td>9<input TYPE=”radio” class=“ratebutton” name=”rating” value=”9″ /></td>
<td>10<input TYPE=”radio” class=“ratebutton” name=”rating” value=”10″ checked=”checked”/>
<input type=”hidden” name=”id_value” value=”<?php print $id_to_rate;?>”/></td><td><INPUT TYPE=submit VALUE=”Vote”></td>
</tr>
</form>
</table>
<table width=”498″ border=”0″ cellspacing=”0″ cellpadding=”0″ align=”center”> <!– photo table (top, left, photo, right, bottom) –>
<tr>
<td colspan=”3″ align=”center”><img src=”Images/rate/frame_top.jpg”></td>
</tr>
<tr>
<td valign=”top” align=”right” width=”49″ class=”frame_left”> </td>
<td align=”center” width=”400″”>
<?php
echo “<img src=’/site/uploaded_files/”.basename($list[‘file’]).”‘ alt=”>”; // call image
//print $list[‘file’];
}
mysql_close($dbh);
?>
[code=html]</td>
<td valign=”top” align=”left” width=”49″ class=”frame_right”> </td>
</tr>
<tr>
<td colspan=”3″ align=”center”><img src=”Images/rate/frame_bottom.jpg”></td>
</tr>
</table>
</table>
</td>
</tr>
<tr>
<td colspan=”2″ vAlign=top bgcolor=”#FFFFFF”><br> <br></td>
</tr>
</table>
<br>
<table width=760 border=0 cellspacing=0 cellpadding=0>
<tr>
<td height=1 bgcolor=B2B3B3></td>
</tr>
<tr>
<td height=2 bgcolor=0B9BFE></td>
</tr>
<tr>
<td ></td>
</tr>
</table>
</div>
</body>
</html>
[/code]