Nix Posted July 21, 2009 Share Posted July 21, 2009 Hi, mates! The following query acts very strange, it returns only 1 result instead of X... I might be doing it wrong somewhere <?php $query = "SELECT ul_user_id, ul_nick, ul_region_id, up_user_id, up_instrument FROM prn_user_list, prn_user_profile WHERE (prn_user_list.ul_region_id='". $region ."') AND (prn_user_list.ul_user_id = prn_user_profile.up_user_id) AND (prn_user_profile.up_instrument = '". $instrument ."')"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "User: ". $row['ul_nick'] ."<br />"; echo "Region: ". $row['ul_region_id'] ."<br /><br />"; } } ?> Tnx in advance! Link to comment https://forums.phpfreaks.com/topic/166789-solved-mysql-query-problem/ Share on other sites More sharing options...
kickstart Posted July 21, 2009 Share Posted July 21, 2009 Hi Looks fine at first glance. What happens if you remove the checks for region and instrument? $query = "SELECT ul_user_id, ul_nick, ul_region_id, up_user_id, up_instrument FROM prn_user_list INNER JOIN prn_user_profile ON prn_user_list.ul_user_id = prn_user_profile.up_user_id"; All the best Keith Link to comment https://forums.phpfreaks.com/topic/166789-solved-mysql-query-problem/#findComment-879506 Share on other sites More sharing options...
Nix Posted July 21, 2009 Author Share Posted July 21, 2009 Tnx for reply Worked fine, listing significant amount of users. Also worked when I added WHERE prn_user_profile.up_instrument='". $instrument ."' at the end, but not when added WHERE prn_user_profile.up_instrument='". $instrument ."' AND prn_user_list.ul_region_id = '". $region ."' Any way that could be fixed? Link to comment https://forums.phpfreaks.com/topic/166789-solved-mysql-query-problem/#findComment-879514 Share on other sites More sharing options...
kickstart Posted July 21, 2009 Share Posted July 21, 2009 Hi Suggests that there is only a single record with a matching instrument AND region. Echo out the SQL just to check what $region is. All the best Keith Link to comment https://forums.phpfreaks.com/topic/166789-solved-mysql-query-problem/#findComment-879519 Share on other sites More sharing options...
Nix Posted July 21, 2009 Author Share Posted July 21, 2009 Oh, I noticed that very few members actually filled out required data (region and instrument from their profiles)! That's why query was returning weird results :D Thank you for your time and effort in solving this "issue", kickstart! King regards!!! Link to comment https://forums.phpfreaks.com/topic/166789-solved-mysql-query-problem/#findComment-879572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.