
December 5th, 2002, 02:09 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Posts: 23
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Here's PHP RatingScript
got this script to work (from retr[] on the site), but i after it runs, i get this error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c: \..\ rate.php on line 19
PHP Code:
<?php
// database variables
$server="localhost"; $user=XXXX"; $pass="XXXXX"; $db="Gallery";
$connection=mysql_connect($server,$user,$pass);
$q="SELECT * FROM photogallery WHERE id='$id' ";
$result= mysql_db_query($db, $q, $connection);
if(!$result)
{
$error_number = mysql_errno();
$error_msg = mysql_error();
echo "MySQL error $error_number: $error_msg";
}
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$title=$row["title"];
$photo=$row["photo"];
$Num_Votes=$row["Num_Votes"];
$Votes =$row["Votes"];
$Rating=$row["Rating"];
$new_Votes=$Num_Votes+1;
$Votes=$Votes+$Rate;
$Rating=round(($Votes/$new_Votes),1);
$q="update photogallery set Num_Votes='$new_Votes', Votes='$Votes', Rating='$Rating' where id='$id'";
$result= mysql_db_query($db, $q, $connection) or die
("Could not execute query : $q." . mysql_error());
if ($result) {
echo "Thank you. The article has rating = $Rating after your vote.";
}
}
?>
*edit: use [ php ] and [ / php ] tags for easy reading*
Last edited by FrankieShakes : December 6th, 2002 at 01:13 PM.
|