Search in online database - Forum

Forum Navigation
You need to log in to create posts and topics.

Search in online database

Hello,
I would like to know how to make a search of a specific data in a online database table. SQL ?
Best regards,
Denis

@cdy44-2 do you mean something like this?
SQL:

SELECT * FROM mytable WHERE mycolumn = "dataToSearch"

In VisualNEO Web would be something like this in config.php:

$sqlAlias[0]="myquery1";
$sqlQuerys[0]="SELECT * FROM mytable WHERE mycolumn=?";
$sqlMaxUserLevel[0]=-1;

And then within your project:

neoPhpExecSql "mydatabase" "myquery1" "dataToSearch" "mysubroutine"

I hope it helps.

 

CDY@44 has reacted to this post.
CDY@44

Hola Luis!:

He tomado esto:

SELECT * FROM mytable WHERE mycolumn = "dataToSearch"

pero quiero hacer esto:

SELECT * FROM mytable WHERE mycolumn = "%dataToSearch%"

Cuando en el config.php coloco los % y en medio el ? pues no funciona. He intentado con comillas simples, dobles y sin comillas sin resultados, existe un reemplazo para "%" en VisualNeo?.

Saludos!

Hola @palamar,

Fíjate que en este caso estás trabajando con PHP. Quiero decir que las soluciones no son específicas de VisualNEO Web ni de neoPHP. De acuerdo a esto, seguramente funcionará así:

SELECT * FROM mytable WHERE mycolumn LIKE "%".?."%"

El punto permite concatenar cadenas en PHP.
Ten cuidado de no poner comillas dobles dentro de otras comillas dobles, utiliza comillas sencillas en su lugar.

@luishp, sí, llevas razón en los puntos, lo obvie por completo, me pasan esas lagunas jajaj, lo pruebo. Mil gracias!.

@luishp pues no ha funcionado, es extraño, si solo pongo el ? busca con el match exacto por lo que la consulta la hace. Así lo he probado (no me ha dejado subir la sintaxis, me ha bloqueado el servidor del foro, no es la primera vez)

 

@palamar

According to this page ... https://www.w3schools.com/sql/sql_wildcards.asp ... it looks like you need to use the LIKE operator (NOT the = sign) when searching with wildcards ... perhaps you can try the syntax below ... just replace {percent-sign-here} with % (because Forum software objects when I try to use actual % signs) ...

SELECT * FROM mytable WHERE mycolumn LIKE "{percent-sign-here}dataToSearch{percent-sign-here}"

Hola, así lo he probado, pero no funciona. Sí busca exactos si remuevo los %.

@palamar

I tried that, but it doesn't work. Yes it looks for exact if I remove the%

1) can you post what database (mySQL, Oracle etc.) that you are using ? (e.g. Microsoft Access uses different wildcard characters than mySQL)

2) in order to pinpoint the root cause, perhaps you can try these one at a time ...

Assuming your client side command is ...

neoPhpExecSql "yourDatabase" "yourAlias" "[varForDataToSearch]" "subroutineToHandleResponse"

a) no wildcards; exact match (I believe you have confirmed that this works)
$sqlQuerys[0]="SELECT * FROM mytable WHERE mycolumn LIKE '?'";

b) begins with dataToSearch and has 0 to many additional characters
$sqlQuerys[0]="SELECT * FROM mytable WHERE mycolumn LIKE '?%'";

c) begins with 0 to many characters but ends with dataToSearch
$sqlQuerys[0]="SELECT * FROM mytable WHERE mycolumn LIKE '%?'";

d) has any 1 character followed by dataToSearch
$sqlQuerys[0]="SELECT * FROM mytable WHERE mycolumn LIKE '_?'";

e) begins with dataToSearch plus any 1 character
$sqlQuerys[0]="SELECT * FROM mytable WHERE mycolumn LIKE '?_'";

Post your results here.

@palamar prueba esto:

SELECT * FROM mytable WHERE mycolumn LIKE CONCAT('%', ?, '%')

Además creo que en las anteriores sentencias faltaba el LIKE

Sí, LIKE estaba, lo agregué despues de tu ejemplo....lo que faltaba en este caso creo que era la sentencia CONCAT y los paréntesis, ha funcionado con esta última. Muchas gracias @luishp y @gaev!!

Open chat
1
Do you need more info?
Hi, do you have any doubt?