PDA

View Full Version : How to check empty columns in a table


spanish_steps
07-05-2003, 03:06 PM
Hello everybody,

How can i do this one??
If i press a button, i have to check if certain columns(fields) in a table are empty.If they are empty, i want to send an e-mail to the e-mail address which is already in this table.If there are no empty columns, then i want to do some calculation using another table.

Could somebody please tell me how should i do.

Many many thanks

raf
07-05-2003, 09:03 PM
do you mean empty columns in a databasetable or in an html-table? And an empty field (no value for that record) or a completely empty column (no value for none of the records)

spanish_steps
07-06-2003, 01:54 PM
Hello Raf,
They are empty columns in a database table.
For example if my table looks like with the following fields:
id,first_name, last_name, address,city,postal_code,email, and so on...

when i press a button, i want to check if the columns(fields)(last_name,address and anyother fields are empty) in this table.

Thanks

raf
07-06-2003, 04:31 PM
Hmm. Not really PHP but whatever.
Now, you didn' answer my second question. (empty field for one record, or empty field for all recordsą

Suppose it's empty fields for 1 record, then use

SELECT Count(*) as thecount FROM table WHERE id=theid and (last_name Is Null or address Is Null or ...)

If thecount is 0, then none of the fields was empty. If it's 1, then one of the fields is empty.
By replacing the OR in the condition by AND, you can check if all variabels for that record were empty

Suppose it's empty fields for all records, then i'm afraid you need to run a select for each field.

Like
SELECT Count(*) as total from table
(to get a reference value)
SELECT Count(*) as countlastname from table WHERE last_name Is Null


If both counts are the same, then all values for last_name were empty.
You'd then need to run the second yuery for each field column, and compaire the count with the count from the first select