0

我有一个从经常更新的数据库中查询的表,以及在哪里

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

和在哪里

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

我需要能够识别排队的人

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

在我的 ajax 中为每个查询的相应行...现在设置的方式,我的 ajax 只会将信息显示回

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

在查询的最后一行....

<?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
}
?>

这是我的 general.js 文件

$(".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); }

    });
}
});
});
});
4

1 回答 1

0

可能是您最新问题的早期版本、 JSON 编码、ajax 并以 html 显示

在我对您关于此问题的最新问题的回答中,我给出了如何在 PHP 和 jQuery 之间使用 JSON 数据的详细示例。

于 2013-02-22T05:24:45.627 回答