0

Ok. Here is the code I have so far...

mysql_query($userrating);
$userratingquery =  "SELECT rating FROM user_rating WHERE user_id=$sellerid";
$userrating = mysql_query($userratingquery) or die('SQL Error :: '.mysql_error());
$userrating = array();

while(($row =  mysql_fetch_assoc($userrating))) {
   $rating[] = $row['rating'];
}

if (!empty($userrating)) {
   $averagerating = array_sum($userratingary); 
   print_r($userratingary);
} else {
   echo '<img src="images/star.png" class="ratingstar" /><img src="images/star.png" class="ratingstar" /><img src="images/halfstar.png" class="ratingstar" />';
}

What I'm trying to do is create an array of the database values called "rating", average the values in that array, then I want to round those values up. So, for instance, if the average of those values ends up being 3.7, then the average will then become 4.

From there I can apply the results to the code... I'm just having a lot of trouble with my array right now. The error I'm getting right now is...

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

Can someone point me in the right direction?

0

1 Answer 1

2

Your problem is here:

$userrating = mysql_query($userratingquery) or die('SQL Error :: '.mysql_error());
$userrating = array();

You are resetting the $userrating variable to an array so when you try to fetch a mysql row the $userrating mysql result is no longer valid.

Use a different variable name for your $userrating array or else another one for your mysql result.

Sign up to request clarification or add additional context in comments.

1 Comment

You were right. Thanks. I also realized that in the while loop I didn't have the array variable set to the same variable I had designated in the first place. That's also why the array wasn't being created.

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.