Jump to content

Recommended Posts

Hey all. Im having a little problem creating a poll. Im running some mySQL functions, and i keep getting this error message:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/fhlinux186/t/toxicgaming.newbiestyle.co.uk/user/htdocs/postpoll.php on line 54

[/quote]

Here's the code im running relative to that area:

[code]

<?php

$db = mysql_connect("****", "****", "***") or die("Could Not Connect");
if(!$db)
    die("no db");
if(!mysql_select_db("******",$db))
    die("No database selected.");

$totaloptions = "5";

$option = mysql_query("SELECT * FROM toxic_poll_results ORDER BY option_number ASC LIMIT " .$totaloptions. "");
    
    while($optionarray=mysql_fetch_assoc($option)) {

        $optionvotes = $optionarray['option_votes'];
        $percent = ($totalvotes / 100) * $optionvotes;

        print '' .$option[$x]. ': <img src="images/bar.gif" width="' .$percent. '" /> ' .$percent. '%<br /><br />';

        $x++;

    }

mysql_close($db);

?>

[/code]

can any body help?
Link to comment
https://forums.phpfreaks.com/topic/11346-mysql-fetch-array-error/
Share on other sites

You'll find that the error you're getting often results from a bad SQL query, like your value for the limit isn't correct or something.

Change this:
[code]$option = mysql_query("SELECT * FROM toxic_poll_results ORDER BY option_number ASC LIMIT " .$totaloptions. "");
    
    while($optionarray=mysql_fetch_assoc($option)) {

        $optionvotes = $optionarray['option_votes'];
        $percent = ($totalvotes / 100) * $optionvotes;

        print '' .$option[$x]. ': <img src="images/bar.gif" width="' .$percent. '" /> ' .$percent. '%<br /><br />';

        $x++;

    }[/code]
To this:
[code]$option = mysql_query("SELECT * FROM toxic_poll_results ORDER BY option_number ASC LIMIT " .$totaloptions. "");
if($option && mysql_num_rows($option) > 0)
{    
    while($optionarray=mysql_fetch_assoc($option)) {

        $optionvotes = $optionarray['option_votes'];
        $percent = ($totalvotes / 100) * $optionvotes;

        print '' .$option[$x]. ': <img src="images/bar.gif" width="' .$percent. '" /> ' .$percent. '%<br /><br />';

        $x++;
}
else
      echo mysql_error();
    }[/code]

Run that and tell us what it says.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.