Thursday, 30 August 2018

PHP & amp; SQL: The subquery does not work

This question already has an answer here:

  • Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in [duplicate] 5 answers
I have the following query with a subquery, this is the php code:
$staticsQuery = "SELECT * FROM statics WHERE mmsi = (SELECT mmsi FROM positions,active WHERE active.mmsi = positions.position_ID)";
$staticsResult = mysql_query($staticsQuery);
        while($rows = mysql_fetch_array($staticsResult)){
            echo $rows['time'];
            echo $rows['mmsi'];
            echo $rows['name'];
            echo $rows['imo'];
        }

The subquery part is normally working, which prints out results. I am not sure if this outer query part is correct: SELECT * FROM statics WHERE mmsi =
This is the error I am getting,
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\retrieve.php on line 44
The error obviously comes from mysql_fetch_array because the query does not return a result. Please don't mark this question as a duplicate, because there can be a lot of different type issues with this error message.
Any help is welcome!

if you will ever have more than one result, you need IN not =

0 comments:

Post a Comment