Foros del Web » Programando para Internet » PHP »

Problema de sintaxis con 'SELECT'.

Estas en el tema de Problema de sintaxis con 'SELECT'. en el foro de PHP en Foros del Web. Hola a todos. Estoy manejando arrays, y quiero usar un array en un select, pero me marca éste error: You have an error in your ...
  #1 (permalink)  
Antiguo 26/06/2009, 07:43
 
Fecha de Ingreso: junio-2009
Mensajes: 250
Antigüedad: 14 años, 9 meses
Puntos: 1
Problema de sintaxis con 'SELECT'.

Hola a todos.

Estoy manejando arrays, y quiero usar un array en un select, pero me marca éste 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 'like 'valordelarray' order by llave ASC limit 0,1' at line 1

Aunque no estoy manejando el array directamente en el 'SELECT', lo estoy haciendo algo así:

Código PHP:
$sintaxis=$data[0]."%";


  
$query_Recordset "SELECT * from reg_obra like '".$sintaxis."' order by llave ASC limit 0,1"
Espero puedan ayudarme, gracias de antemano.

Saludos.
  #2 (permalink)  
Antiguo 26/06/2009, 07:52
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Problema de sintaxis con 'SELECT'.

Te falta el WHERE

$query_Recordset = "SELECT * from reg_obra WHERE nombre_de_la_columna_a_verifica like '".$sintaxis."' order by llave ASC limit 0,1";
  #3 (permalink)  
Antiguo 26/06/2009, 07:57
Avatar de argy  
Fecha de Ingreso: octubre-2007
Ubicación: Longitud 75º Latitud 18º Sur
Mensajes: 614
Antigüedad: 16 años, 4 meses
Puntos: 18
Respuesta: Problema de sintaxis con 'SELECT'.

un aporte utiliza LIMIT con OFFSET es más rápido.

suerte.
__________________
Software libre para un mundo libre.

Eventualmente en el foro.
  #4 (permalink)  
Antiguo 26/06/2009, 08:17
 
Fecha de Ingreso: junio-2009
Mensajes: 250
Antigüedad: 14 años, 9 meses
Puntos: 1
Respuesta: Problema de sintaxis con 'SELECT'.

¿Cómo sería el OFFSET ahí?
  #5 (permalink)  
Antiguo 26/06/2009, 08:29
Avatar de argy  
Fecha de Ingreso: octubre-2007
Ubicación: Longitud 75º Latitud 18º Sur
Mensajes: 614
Antigüedad: 16 años, 4 meses
Puntos: 18
Respuesta: Problema de sintaxis con 'SELECT'.

aqui tienes un TIP

http://www.mysql-hispano.org/index.php?m=read&id=1474
__________________
Software libre para un mundo libre.

Eventualmente en el foro.
  #6 (permalink)  
Antiguo 26/06/2009, 09:54
 
Fecha de Ingreso: junio-2009
Mensajes: 250
Antigüedad: 14 años, 9 meses
Puntos: 1
Respuesta: Problema de sintaxis con 'SELECT'.

Me surgió otro problema, tengo un while así:

Código PHP:
$data2=0;
while ((
$data fgetcsv($handle4096',')) !== FALSE) {
$data str_replace("'","''",$data);
if(
$data!=$data2){

$sintaxis=$data[0]."%";


  
$query_Recordset "SELECT * from otratabla WHERE llave like '".$sintaxis."' order by llave ASC limit 0,1";
$Recordset mysql_query($query_Recordset$conex) or die(mysql_error());
$row_Recordset mysql_fetch_assoc($Recordset);
$clave=$row_Recordset['llave'];
$data2=$data[0];
}

$import="INSERT into tabla(clave,campo2,campo3,campo4) values('$clave','$data[1]','$data[2]','$data[3]')";
$clave++;
$runq mysql_query($import) or die(mysql_error());
echo 
$import;
echo 
"<br>";

Y me marca éste error:
Código PHP:
NoticeUndefined offset1 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset2 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset3 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset4 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset5 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset6 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset7 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset8 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset9 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset10 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset11 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset12 in C:wampwwwsitiopruebacsv2.php on line 42

Notice
Undefined offset13 in C:wampwwwsitiopruebacsv2.php on line 42 
La línea 42 es ésta:

Código PHP:
$import="INSERT into tabla(clave,campo2,campo3,campo4) values('$clave','$data[1]','$data[2]','$data[3]')"
Sin mencionar que pasa varias veces por el 'if', cuando sólo debería pasar la primera vez, o en caso de que cambie el valor de '$clave'
¿Qué es lo causa o cómo puedo resolverlo?

Gracias de antemano, saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:40.