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); ... Link to comment https://forums.phpfreaks.com/topic/174072-mysql_num_rows-problem-php-or-mysql-error/ 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(); Link to comment https://forums.phpfreaks.com/topic/174072-mysql_num_rows-problem-php-or-mysql-error/#findComment-917603 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 Link to comment https://forums.phpfreaks.com/topic/174072-mysql_num_rows-problem-php-or-mysql-error/#findComment-917605 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. Link to comment https://forums.phpfreaks.com/topic/174072-mysql_num_rows-problem-php-or-mysql-error/#findComment-917614 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? Link to comment https://forums.phpfreaks.com/topic/174072-mysql_num_rows-problem-php-or-mysql-error/#findComment-917616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.