Andrew R Posted February 6, 2009 Share Posted February 6, 2009 Can anybody see why the following sql query gives an mysql_error? $clients_q = mysql_query("SELECT * FROM organisations where organisation_Id = (SELECT organisation_id FROM hosting WHERE server_id = '1')") or die(mysql_error); $clients = mysql_fetch_array($clients_q); $total_users = mysql_num_rows($clients_q); Many thanks Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/ Share on other sites More sharing options...
JonnoTheDev Posted February 6, 2009 Share Posted February 6, 2009 Are your field names correct? organisation_Id = (SELECT organisation_id What is the error? Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755901 Share on other sites More sharing options...
Andrew R Posted February 6, 2009 Author Share Posted February 6, 2009 Thanks for the reply. All fields are correct and the error is 'mysql_error'. Many thanks. Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755908 Share on other sites More sharing options...
JonnoTheDev Posted February 6, 2009 Share Posted February 6, 2009 Change your code to: or die(mysql_error()); And then give us the error Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755917 Share on other sites More sharing options...
aschk Posted February 6, 2009 Share Posted February 6, 2009 How about you try using a JOIN instead: SELECT o.* FROM organisations o JOIN hosting h ON h.organisation_id = o.organisation_Id WHERE h.server_id = '1' Something tells me the error might be related to the fact that your subquery returned more than 1 resulting row. Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755967 Share on other sites More sharing options...
Maq Posted February 6, 2009 Share Posted February 6, 2009 Should organisation_Id be (lowercase i) ? organisation_id Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755975 Share on other sites More sharing options...
JonnoTheDev Posted February 6, 2009 Share Posted February 6, 2009 Already asked that Maq Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755977 Share on other sites More sharing options...
Maq Posted February 6, 2009 Share Posted February 6, 2009 Already asked that Maq Sorry, yeah I just skimmed over and thought you were asking something else (obviously). Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-755980 Share on other sites More sharing options...
aschk Posted February 6, 2009 Share Posted February 6, 2009 It doesn't matter if it's upper, lower or combo case. MySQL doesn't care about cases for columns , it ONLY cares about cases for table names. Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-756090 Share on other sites More sharing options...
fenway Posted February 8, 2009 Share Posted February 8, 2009 Yes, you'd need IN, not =. Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-757358 Share on other sites More sharing options...
ashishag67 Posted February 8, 2009 Share Posted February 8, 2009 why dont you try this $client_q=mysql_query("SELECT * FROM organisations o, hosting h where o.organisation_Id=h.server_id='1'") or die(mysql_error()); $client=mysql_fetch_array($client_q); $total_users=mysql_num_rows($client_q); Do let me know if this works. Cheers Link to comment https://forums.phpfreaks.com/topic/144062-subquery-mysql_error/#findComment-757363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.