Jim R Posted August 15, 2011 Share Posted August 15, 2011 Let me start by saying this is my attempt at coding with anything involving a Join, on my own at least. It's failed. : ) I'm trying to match the Tags of Images so they show up on the related Tag Archive page (mostly basketball players for me). I know the first line works and brings the tag_id in so it can be used. The datatable where the images are stored is wp_ngg_pictures. Logically it goes like this: np.pid (128,140,147) = tr.object_id (128,140,147) tr.term_taxonomy_id (1200) = tt.term_taxonomy_id (1200) tt.term_id (where taxonomy = ngg_tag) (517) = t.term_id (where t.term_id = $wp_tagID) (517) $wp_tagID = get_query_var('tag_id'); $qImage = 'SELECT * FROM wp_ngg_pictures AS np LEFT JOIN wp_term_relationships AS tr ON np.pid = tr.object_id LEFT JOIN wp_term_taxonomy_id AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN wp_terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = ngg_tag AND t.term_id = "$wp_tagID" '; $pImage = mysql_query($qImage); while($images = mysql_fetch_assoc($pImage)) { <-- line 109 <--- echo $images; } I'm getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/jwrbloom/public_html/resources/wp-playerProfile.php on line 109 Quote Link to comment https://forums.phpfreaks.com/topic/244806-needing-wordpress-database-query-help/ Share on other sites More sharing options...
Jim R Posted August 15, 2011 Author Share Posted August 15, 2011 I am also trying to get help on the WordPress forums too. Quote Link to comment https://forums.phpfreaks.com/topic/244806-needing-wordpress-database-query-help/#findComment-1257529 Share on other sites More sharing options...
trq Posted August 15, 2011 Share Posted August 15, 2011 That error is caused by simply passing the result of mysql_query to mysql_fetch_assoc without firstly checking to see if your query actually succeeds or not. I swear I post this at least a few times a day: if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result holds records } else { // no record found, handle error } } else { // query failed, handle error } To give you a hint as to why your query is failing take a look at the output from mysql_error. Quote Link to comment https://forums.phpfreaks.com/topic/244806-needing-wordpress-database-query-help/#findComment-1257545 Share on other sites More sharing options...
Jim R Posted August 15, 2011 Author Share Posted August 15, 2011 I appreciate the link, but your code doesn't really help me. It just changes the output when I get an error vs. when the query produces nothing. In this instance it's likely both, and I'm really trying to work my way through Joins. What I've read on them doesn't give me much to go on, and that includes searching here and reading MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/244806-needing-wordpress-database-query-help/#findComment-1257676 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.