visionaire Posted October 27, 2010 Share Posted October 27, 2010 I have a strange error from the code below. I have run the query with the resulting values in PHPMyAdmin and it works fine. The code is: $query = "SELECT * FROM sn_matches WHERE (P1_ID='".$P1_ID."' AND P2_ID='".$P2_ID."') OR (P1_ID='".$P2_ID."' AND P2_ID='".$P1_ID."')"; while($row = mysql_fetch_assoc($query)){ The error is: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in /customers/ronflorax.com/ronflorax.com/httpd.www/snookerstats/h2h.php on line 21 Line 21 is the one which has mysql_fetch_assoc on it. Any help would be much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/216978-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-string-given-in/ Share on other sites More sharing options...
Adam Posted October 27, 2010 Share Posted October 27, 2010 You're not actually making a query; you first need to pass the SQL code to mysql_query, and then pass the returned resource to mysql_fetch_assoc. Quote Link to comment https://forums.phpfreaks.com/topic/216978-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-string-given-in/#findComment-1127020 Share on other sites More sharing options...
visionaire Posted October 27, 2010 Author Share Posted October 27, 2010 Just what I needed, thank you so much! Is there a reason why sometimes I need to run it through mysql_query and sometimes I don't? Quote Link to comment https://forums.phpfreaks.com/topic/216978-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-string-given-in/#findComment-1127021 Share on other sites More sharing options...
Adam Posted October 27, 2010 Share Posted October 27, 2010 You always have to use mysql_query() to send a query, when using the MySQL extension of course. Quote Link to comment https://forums.phpfreaks.com/topic/216978-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-string-given-in/#findComment-1127026 Share on other sites More sharing options...
visionaire Posted October 27, 2010 Author Share Posted October 27, 2010 OK great, thanks for clearing this up for me! Quote Link to comment https://forums.phpfreaks.com/topic/216978-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-string-given-in/#findComment-1127029 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.