By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

how to ignore the empty fields of a database?

P: 10
In my database, some fields are empty for some recordings.
And I wouldl like that the empty fields donīt appear on the answer page of my search engine or, in other worlds, that I donīt have that kind of things (ie age without anything):
Surname : Sawers
First name : Tom
Age:
Nationality : American
Thanks a million!
Jun 22 '07 #1
Share this Question
Share on Google+
5 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Raphaelle.

You can check for IS NOT NULL in the WHERE clause of your query:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `theTable` WHERE `Age` IS NOT NULL
Jun 23 '07 #2

P: 10
In my database, some fields are empty for some recordings.
And I wouldl like that the empty fields donīt appear on the answer page of my search engine or, in other worlds, that I donīt have that kind of things (ie age without anything):
Surname : Sawers
First name : Tom
Age:
Nationality : American

I tried it but I got a result I didnīt expect.
If I put the IS NULL in the WHERE clause, I donīt get the file of Tom Sawers anymore and thatīs not what I want.
I would like the file appear like that
Surname : Sawers
First name : Tom
Nationality : American
The Age field doesnīt have to appear in this case because it hasnīt been filled.
Does it exist a way to do that?
thanks again for your help
Jun 25 '07 #3

code green
Expert 100+
P: 1,726
To filter the individual fields out of your recordset becomes a bit complicated.
It is probably tidier to filter them with your php code by checking if the array variable is empty. [PHP]while($record = mysql_fetch_assoc($result)
{
if(!empty($record['age']))
echo 'age '.$record['age'];
}[/PHP]
Jun 26 '07 #4

pbmods
Expert 5K+
P: 5,821
Heya, Raphaelle.

You can instead use
Expand|Select|Wrap|Line Numbers
  1. AND `age` <> ''
.
Jun 26 '07 #5

P: 10
It works!! thanks a lot for the tip
Jun 27 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.