kingnutter Posted September 13, 2009 Share Posted September 13, 2009 Hi there, I am trying to JOIN two databases and retrieve the number of rows. I keep getting the error message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\web\mojo\php-files\edit_mojo_cd.php on line 453 Could anyone give the code below a short scan at let me know if the problem might be the MySQL query or the mysql_num_rows line. Or both? Thanks. KN foreach ($missing_genres as $row) { $query="SELECT * FROM genrelinkcd WHERE genrelinkcd.genre_id=genres.genre_id WHERE genres.moj_genre='$row'"; $result = mysql_query($query); $amount = mysql_num_rows($result); ... Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 13, 2009 Share Posted September 13, 2009 before mysql_num_rows, but after mysql_query, type this echo mysql_error(); Quote Link to comment Share on other sites More sharing options...
cbolson Posted September 13, 2009 Share Posted September 13, 2009 Hi, Your query is wrong - you have 2 WHERE statements in there. $query="SELECT * FROM genrelinkcd WHERE genrelinkcd.genre_id=genres.genre_id WHERE genres.moj_genre='$row'"; I can't quite work out what you are trying to do with that query so I can't actually suggest what it should lool like. Chris Quote Link to comment Share on other sites More sharing options...
kingnutter Posted September 13, 2009 Author Share Posted September 13, 2009 I have two tables: 1) 'genres' containing moj_genre and genre_id 2) 'genrelinkcd' containing id, genre_id and moj_id Basically. I want to know how many times a moj_genre occurs in 'genrelinkcd' the link being genre_id in both tables. Quote Link to comment Share on other sites More sharing options...
ShaunO Posted September 13, 2009 Share Posted September 13, 2009 SELECT * FROM genres g INNER JOIN genrelinkcd gl ON g.genre_id = gl.genre_id WHERE g.moj_genre = '$row' Is that what you're after? Quote Link to comment 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.