1
I’m creating a system in PHP and in it has a Script which selects the data of the module requested by the user. The Script creates the form to view and edit the data according to the information of the table fields. The problem I’m facing is that when the request is an inclusion of record, still need to be made a Select in the table so that the form fields are displayed correctly, which is not happening. I need the query to return an empty record so that the Script can read the information of the fields.
The Select is as follows:
select ID, DATA, DESCRICAO from FERIADOS where (ID = 0)
I’ve tried it many ways, but when it doesn’t come back, it all comes back:
select null, ID, DATA, DESCRICAO from FERIADOS where (ID = 0) //Não retorna nada
select ID, DATA, DESCRICAO from FERIADOS where (ID = 0) or (1=1) //Retorna todos os registros
select ID, DATA, DESCRICAO from FERIADOS where (ID = 0) and (1=1) //Não retorna nada
select coalesce(ID,''), coalesce(DATA,''), coalesce(DESCRICAO,'') from FERIADOS where (ID = 0) //Não retorna nada
select first 1 ID, DATA, DESCRICAO from FERIADOS //Eu poderia utilizar esse, mas há casos de tabelas vazias e ainda terei que zerar os valores dos campos
I thought of creating Stored Procedure to empty each field if the query was empty, but it is impossible to maintain the code, because I would have to create a SP for each table and the idea of the project is to use only one Script for each type of request.
Which function I could add in Select for the query to show the fields even if it returns no record?
Sidon, this way would work yes, but in my case I would really need a way for the fields to come in the table select. It’s just that Select is unique, but if I don’t get any hints of a function I could use on it, I’ll use your example. Thank you!
– Carlos Andrade
Just check if I was empty, use the example and create the form. I’ll edit it so you can get more detailed information about the fields
– Sidon
Do you have any idea what I might add to the clause
where
from my Select to return an empty query? eg:select ID, DATA, DESCRICAO from FERIADOS where (ID = 0) or ?????
– Carlos Andrade
Okay Sidon, thank you so much for your time. I will adapt your code, it will surely work.
– Carlos Andrade
Man, I’ve never seen this, it seems strange to the concept of
SELECT
SQL. The only way I can imagine without creating procedures in the database would be to create 'empty' records in the tables.– Sidon
Forget the way you did and use my example to assemble the Formularios, before even making the "real" query. That’s how we created dynamic formulas when I used FB. :-)
– Sidon