Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: perro88 - joulukuu 26, 2007, 01:58:58 IP

Otsikko: need some help here
Kirjoitti: perro88 - joulukuu 26, 2007, 01:58:58 IP
I'm trying to make a rate system on my movies board. For that I created 2 tables:
1)table "Movies" with fields "movieID(same as topicID,n_votes(number of votes),rating(average))
2)table "MoviesVotes" with fields (movieID,userID,rating(1 to 10 integer)
I already made the code so when someone create a topic in the movies board it will also create an entry on the Movies table where the moviesID field would be the topicID and initialized the rating and n_votes fields to 0(zero).
Now I made the changes on dysplay.php and dysplay.template  but I'm having some problems.
One of the problem is that the forms seems that are not sending the values  ::) and other one is that when I click the submit button of the form a popup message appear(something like "Are you sure to continue"). here's what i made:
dysplay.php:
// Load the proper template and/or sub template.
if (WIRELESS)
$context['sub_template'] = WIRELESS_PROTOCOL . '_display';
else
loadTemplate('Display');

// movie rate system
if (isset($_REQUEST['Reset']) && !$user_info['is_guest'])
{
db_query("
DELETE *FROM {$db_prefix}MoviesVotes WHERE userID = $ID_MEMBER AND movieID=$topic", __FILE__, __LINE__);

}

$request = db_query("
SELECT *FROM {$db_prefix}MoviesVotes WHERE userID = $ID_MEMBER AND movieID=$topic", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
if($row) 
{
$context['already_voted']=true;
$context['past_rate']=$row['rating'];
}
else
   $context['already_voted']=false;

if (isset($_REQUEST['Rate']) && !$user_info['is_guest'])
{
$rating = (int) $_POST['vote'];
if ($rating >= 1 && $rating <= 10)
db_query("
REPLACE INTO {$db_prefix}MoviesVotes
(userID, movieID, rating)
VALUES
($ID_MEMBER, $topic, $rating)", __FILE__, __LINE__);
$request = db_query("SELECT COUNT(*) AS n_votes FROM {$db_prefix}MoviesVotes WHERE movieID=$topic", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
$request = db_query("SELECT AVG(vote) AS average FROM {$db_prefix}MoviesVotes WHERE movieID=$topic", __FILE__, __LINE__);
$row2 = mysql_fetch_assoc($request);
$rating = number_format($row2['average'], 2, '.', ");
db_query("UPDATE {$db_prefix}Movies SET n_votes='$row['n_votes']', average='$rating' WHERE movieID=$topic", __FILE__, __LINE__);
}

dysplay.template:
if($context['user']['is_logged'])
{
if($context['already_voted'])
{


echo '<b>',$context['past_rate'],'</b>&nbsp;<form action="', $scripturl, '?topic=', $context['current_topic'], ' method="POST" style="margin: 0;">
<input type="hidden" name="sc" value="', $context['session_id'], '" />
<input type="submit" name="Reset" value="Reset" />
</form>';
}
else
{
echo '

<form action="', $scripturl, '?topic=', $context['current_topic'], ' method="POST" style="margin: 0;">
<select name="vote">';
for ($i = 1; $i <= 10; $i++)
echo '
<option value="', $i, '">', $i, '</option>';
echo '
</select>
<input type="hidden" name="sc" value="', $context['session_id'], '" />
<input type="submit" name="Rate" value="Rate" />
</form>';
}
}
else
{
echo'You need to be loged in order to rate this movie';
}

I made some testing and noticed that seems that the forms are not submiting the values it should and also that this IF is not executing(this means, when i click the reset button the if didn't execute the code in it, off course might be related to the forms that are not submiting values):"if (isset($_REQUEST['Reset']) && !$user_info['is_guest'])"