Syntax of this query [closed]

0

I have this query

$CeanLibre = "SELECT min('3') + 1 as prox_ean_libre FROM (SELECT 0 AS '3' union all SELECT '3' FROM 'Direcciones&Codigos' WHERE '3' BETWEEN 
'".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' AND 
'".$CCodEan[2].$CCodEan[3].$CCodEan[5]."' ) 't1' WHERE not exists (select null 
FROM 'Direcciones&Codigos' t2 WHERE 't2.3' = 't1.3' + 1 AND 't2.3' BETWEEN 
'".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' AND 
".$CCodEan[2].$CCodEan[3].$CCodEan[5]."' )"; //miramos de nuevo el ultimo codigo por si aca

    $REanLibre = mysqli_query($Conectar ,$CeanLibre); //pongo un resultado de la consulta

    $DEanLibre=mysqli_fetch_array($REanLibre); 

    $EanLibre = trim($DEanLibre["prox_ean_libre"]);

But I get an error.

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near '' )' at line 1

<b>Warning</b>:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in

I think it's for some ' and I do not know if the syntax would be that. "3" is the name of a mysql column

I also have this one that is similar and does not fail:

$CIdmaxFactS = "SELECT MAX(CAST('3' AS UNSIGNED)) AS ultimoean FROM 'Direcciones&Codigos' WHERE '3' BETWEEN '".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' AND '".$CCodEan[2].$CCodEan[3].$CCodEan[5]."' ";
    $RIdmaxFactS = mysqli_query($Conectar ,$CIdmaxFactS);
    $DIdmaxFactS=mysqli_fetch_array($RIdmaxFactS); 
    $idmaxFactS = trim($DIdmaxFactS["ultimoean"]);

The only thing that in this second looks for the last number and I need you to look at the first one that is free.

Can someone help me out? to see if you see something that escapes me.

    
asked by Killpe 15.02.2017 в 23:11
source

1 answer

2

A single quote (') is missing in the last line of the query. I leave the query resolved. I hope it helps you.

$CeanLibre = "SELECT min('3') + 1 as prox_ean_libre 
                FROM (
                     SELECT 0 AS '3' 
                      union all 
                            SELECT '3' 
                              FROM 'Direcciones&Codigos' 
                              WHERE '3' BETWEEN  '".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' AND  '".$CCodEan[2].$CCodEan[3].$CCodEan[5]."' 
                     ) 't1' 
               WHERE not exists (
                     select null  
                       FROM 'Direcciones&Codigos' t2 
                      WHERE 't2.3' = 't1.3' + 1 
                        AND 't2.3' BETWEEN '".$CCodEan[2].$CCodEan[3].$CCodEan[4]."' 
                                       AND '".$CCodEan[2].$CCodEan[3].$CCodEan[5]."'
               --                         ^^^ 
                                )";
    
answered by 16.02.2017 / 01:00
source