开发者

MySQL update table on vote script

开发者 https://www.devze.com 2023-02-12 12:47 出处:网络
I have a voting script on my message board. When somebody votes, it uses 开发者_StackOverflow中文版vote.php:

I have a voting script on my message board. When somebody votes, it uses 开发者_StackOverflow中文版vote.php:

$check_query = " insert into m_votes set votes = {$vote_type}, ip = '$user_ip', messageid = $mid, name = '$name', messageby = '$mbu'";

    $check_query_result = mysql_query($check_query) or die(mysql_error());

    // return back total votes
    $votes_query = "select sum(votes) as votes from m_votes where messageid = $mid";
    $votes_query_result = mysql_query($votes_query) or die(mysql_error());
    $votes_query_row = mysql_fetch_array($votes_query_result);
    echo $votes_query_row['votes'];

    // update score on guestbook_message table
    $update = "UPDATE guestbook_message SET score = $votes_query";

The problem is with the last line of code. The 'score' field is on a different table to the one the votes information is held.I just want it so that when somebody votes on a message, it gets the sum of votes for that message, and updates the 'score' field on the guestbook_message table. But the code I have doesn't do this. it doesn't show a syntax error either.


$update = 'UPDATE guestbook_message SET score = ' . $votes_query_row['votes'];
mysql_query($update) or die(mysql_error());
0

精彩评论

暂无评论...
验证码 换一张
取 消