- Joined
- Feb 17, 2008
- Posts
- 678
- Reaction score
- 13
I have some code which calls a php script and replaces an image. This works all well and good but Im looking to improve it but I just cant figure out how to get it to do what I want.
The current code is:
The click part is:
Then the php part:
ideal situation would be for a click to remove the full content of the thumb$id div and let me replace it with code from the called script.
Any jQuery gurus?
The current code is:
PHP:
$(function() {
$(".vote").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(20000).html('<img class="thumb" src="images/upg.png" align="absmiddle">');
$.ajax({
type: "POST",
url: "upvote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(here);
} });
}
else
{
$(this).fadeIn(200).html('<img class="thumb" src="images/downr.png" align="absmiddle">');
$.ajax({
type: "POST",
url: "downvote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
return false;
});
});
The click part is:
PHP:
<div class="thumb<?php echo $id; ?>">
<a href="" class="vote" id="<?php echo $id; ?>" name="up"><img class="thumb" src="images/up.png" align="absmiddle"></a>
<a href="" class="vote" id="<?php echo $id; ?>" name="down"><img class="thumb" src="images/down.png" align="absmiddle"></a></div>
Then the php part:
PHP:
<?php
include("config.php");
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$ip=$_SERVER['REMOTE_ADDR'];
if($_POST['id'])
{
$id=$_POST['id'];
$id = mysql_escape_String($id);
$ip_sql=mysql_query("select ip_add from logip where quo_id_fk='$id' and ip_add='$ip'");
$count=mysql_num_rows($ip_sql);
if($count==0)
{
$sql = "update quotes set vote=vote+1 where id='$id'";
mysql_query( $sql);
$sql_in = "insert into logip (quo_id_fk,ip_add) values ('$id','$ip')";
mysql_query( $sql_in);
//echo "<script>alert('Debug, ID: $id IP: $ip');</script>";
}
else {
//maybe do something if $count !=0
}
echo '<img class="thumb" src="images/up.png" align="absmiddle">';
}
?>
ideal situation would be for a click to remove the full content of the thumb$id div and let me replace it with code from the called script.
Any jQuery gurus?