0

I have a table that queries from a database that is updated frequently, and where

<span id="totalvotes1"></span>

and where

<span id="totalvotes2"></span>

I need to be able to be able to identify those in the line

success: function(data) { $('#totalvotes1').text(data); } });

in my ajax for each corresponding row queried... the way it is set up right now, my ajax will just display the information back into

<span id="totalvotes1"></span>

in the last row queried....

<?php

$sql = mysql_query("SELECT * FROM blogData ORDER BY id DESC");
$sql2=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 0 ORDER BY mes_id DESC");
$sql3=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 1 ORDER BY mes_id DESC");

$count_variable = 0;

while(($row = mysql_fetch_array($sql))AND($row2 = mysql_fetch_array($sql2))AND($row3 = mysql_fetch_array($sql3)) ){
    $id = $row['id'];
    $title = $row['title'];
    $content = $row['content'];
    $category = $row['category'];
    $podcast = $row['podcast'];
    $datetime = $row['datetime'];

    $message1=$row2['msg'];
    $mes_id1=$row2['mes_id'];
    $totalvotes1=$row2['totalvotes'];

    $message2=$row3['msg'];
    $mes_id2=$row3['mes_id'];
    $totalvotes2=$row3['totalvotes'];


?>

<table class="content">
<tr>
<td>


<div id="main">
<div id="left">
<span class='up'><a href="" class="vote" name="up" data-options="key1=<?php echo $mes_id1;?>&key2=<?php echo $mes_id2;?>"><img src="up.png" alt="Down" /></a></span><br />
<span id="totalvotes1"><?php echo $totalvotes1; ?></span><br />
</div>
<div id="message">
<?php echo $message1; ?>
</div>
<div class="clearfix"></div>
</div>
<div id="main">
<div id="right">
<br />
<span id="totalvotes2"><?php echo $totalvotes2; ?></span><br />
<span class='down'><a href="" class="vote" name="down" data-options="key1=<?php echo $mes_id1;?>&key2=<?php echo $mes_id2;?>"><img src="down.png" alt="Down" /></a></span>
</div>
<div id="message">
<?php echo $message2; ?>
</div>
<div class="clearfix"></div>
</div>
</td>
</tr>
</table>

<?php
}
?>

here is my general.js file

$(".vote").click(function()  
{
    var id = $(this).attr("id");
    var name = $(this).attr("name");
    var eData = $(this).attr("data-options");
    var dataString = 'id='+ id + '&' + eData ;
    var parent = $(this); 

    if(name=='up')
    {
        $(this).fadeIn(200).html('');
        $.ajax({
            type: "POST",
            url: "up.php",
            data: dataString,
            cache: false,
            success: function(data) { $('#totalvotes1').text(data); }
    });

}
else
{
    $(this).fadeIn(200).html('');
    $.ajax({
        type: "POST",
        url: "down.php",
        data: dataString,
        cache: false,
        success: function(data) { $('#totalvotes2').text(data); }

    });
}
});
});
});
9
  • thank you in advance to anyone who takes the time to help me out... Commented Feb 21, 2013 at 7:09
  • if anyone has links... or examples.... I mean anything would help.... does anybody know if this is even possible or am I just completely screwed...? Commented Feb 21, 2013 at 7:22
  • the way to do it would be to encode your result in json -> json_encode() and your receiving js to decode it Commented Feb 21, 2013 at 7:25
  • thank you, I have absolutely no idea how to work with json or how I'd implement that here but i will go research it. thank you Commented Feb 21, 2013 at 7:27
  • still looking for help... I don't understand how to implement json here.... Commented Feb 21, 2013 at 7:53

1 Answer 1

0

Possibly a earlier version of your latest question, JSON encode, ajax and display back in html

In my answer on your latest question about this, I've given a detailed example of how to use JSON data between PHP and jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.