Jump to content

Subquery mysql_error


Andrew R

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.