MySQL double query situation

Is there any other way to make this request?

 $query = "SELECT * FROM produto, pt WHERE
        produto.refPT = pt.ref AND
        produto.refPT IN (SELECT idProduto FROM amb_prod WHERE idAmbiente='1');";
    $result_set = mysql_query($query);

      

The problem is my localhost has MySQL version 5.1.30-community, but my internet server has MySQL version 5.0.67-community.

And I think the reason I am getting this error is only when I try to run on an online server:

mysql_fetch_array(): supplied argument is not a valid MySQL result resource 

      

0


a source to share


4 answers


It makes life easier when you create a beautiful look for your query like:



$query = "SELECT *
          FROM produto, pt, amb_prod 
          WHERE produto.refPT = pt.ref
          AND produto.refPT = amb_prod.idProduto 
          WHERE amb_prod.idAmbiente='1';";
$result_set = mysql_query($query);

      

+1


a source


well it would be wise to install a suitable MySQL version in your test systems so you can debug the bug more easily.

You can also try something like this ...



$query = "SELECT * FROM produto, pt, amb_prod WHERE
    produto.refPT = pt.ref AND
    produto.refPT = amb_prod.idProduto WHERE amb_prod.idAmbiente='1');";
$result_set = mysql_query($query);

      

0


a source


At the very least, to simplify your query, you can go with:

"Select * from produto,pt,amb_prod WHERE
       produto.refPT = pt.ref AND
       produto.refPT=amb_prod.idproduto AND
       amb_prod.idAmbiente='1';"

      

Although I would recommend choosing fields rather than "*". I also need to wonder why you are quoting "1" is it not a numeric field?

0


a source


Get rid of the comma at the end and see if that helps.

In some bridging implementations (the one that ties your language to the MySQL server), your query string is actually two queries:

SELECT * 
FROM produto, pt 
WHERE
 produto.refPT = pt.ref AND
 produto.refPT IN (SELECT idProduto 
                   FROM amb_prod 
                   WHERE idAmbiente='1')

      

AND...

[Blank]

      

Some bridges can get confused about both what result will be returned (SQL result or empty query) and whether an empty query is acceptable or not.

0


a source







All Articles