slipperyfish Posted June 6, 2006 Share Posted June 6, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/11346-mysql-fetch-array-error/ Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11346-mysql-fetch-array-error/#findComment-42489 Share on other sites More sharing options...
.josh Posted June 6, 2006 Share Posted June 6, 2006 [code]$option = mysql_query("SELECT * FROM toxic_poll_results ORDER BY option_number ASC LIMIT " .$totaloptions);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11346-mysql-fetch-array-error/#findComment-42490 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 The query should have worked as he had it.... I'm really thinking his $totaloptions variable is empty. Quote Link to comment https://forums.phpfreaks.com/topic/11346-mysql-fetch-array-error/#findComment-42492 Share on other sites More sharing options...
slipperyfish Posted June 6, 2006 Author Share Posted June 6, 2006 ahh thanks. when i used that the mysql eror revealed iwas trying to get out of the table "toxic_poll_results", should have been "toxic_poll_options", silly mistake! Thankyou for your help kind sirS. Quote Link to comment https://forums.phpfreaks.com/topic/11346-mysql-fetch-array-error/#findComment-42493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.