xiaoxin22 Posted July 1, 2010 Share Posted July 1, 2010 i did this.. $query2 = sprintf("SELECT * FROM (c_details INNER JOIN c_color ON c_details.cc_id = c_color.cc_id) WHERE c_color.cc_id = %s", mysql_real_escape_string($colour)); $result2 = mysql_query($query2); $print2 = mysql_fetch_assoc($result2); it is working but it keep showing error message.. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/sip/public_html/test/calender.php on line 90 can someone tell me what's wrong with it? Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/ Share on other sites More sharing options...
Ruzzas Posted July 1, 2010 Share Posted July 1, 2010 WHERE %s? I don't think PHP Supports that. Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079552 Share on other sites More sharing options...
xiaoxin22 Posted July 1, 2010 Author Share Posted July 1, 2010 it's working.. cause i use this for all my php.. but never encounter this problem before.. Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079553 Share on other sites More sharing options...
aneesme Posted July 1, 2010 Share Posted July 1, 2010 Are you sure you selected a database? Regards, Anees http://ask.amoeba.co.in Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079558 Share on other sites More sharing options...
xiaoxin22 Posted July 1, 2010 Author Share Posted July 1, 2010 yea.. everything is fine.. it is appearing.. what bothers me is that error message... Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079560 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 That error message indicates that whatever you are passing to mysql_fetch_assoc on line 90 is not a result resource. Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079562 Share on other sites More sharing options...
xiaoxin22 Posted July 1, 2010 Author Share Posted July 1, 2010 what does it mean by not result resource? can elaborate more? Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079564 Share on other sites More sharing options...
robert_gsfame Posted July 1, 2010 Share Posted July 1, 2010 Single quotes missing %s should be '%s' Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079566 Share on other sites More sharing options...
xiaoxin22 Posted July 1, 2010 Author Share Posted July 1, 2010 OH!! AMAZING!!! it works!!! thank you very much.. i will continue to work on it.. Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079568 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 The problem is you where passing $result2 to mysql_fetch_assoc without first checking to make sure your query succeeded. mysql_fetch_assoc expects a result resource, which is what mysql_query returns if it succeeds, but when it fails it returns false. While your at it, you should likely check your query returns some records as well. $query2 = sprintf("SELECT * FROM (c_details INNER JOIN c_color ON c_details.cc_id = c_color.cc_id) WHERE c_color.cc_id = %s", mysql_real_escape_string($colour)); if ($result2 = mysql_query($query2)) { if (mysql_num_rows($result2)) { $print2 = mysql_fetch_assoc($result2); } else { // no records found. } } else { // query failed } Link to comment https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/#findComment-1079572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.