how to ignore the empty fields of a database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Phaelle
    New Member
    • Jun 2007
    • 10

    how to ignore the empty fields of a database?

    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!
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Raphaelle.

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

    [code=mysql]SELECT * FROM `theTable` WHERE `Age` IS NOT NULL[/code]

    Comment

    • Phaelle
      New Member
      • Jun 2007
      • 10

      #3
      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

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        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_ass oc($result)
        {
        if(!empty($reco rd['age']))
        echo 'age '.$record['age'];
        }[/PHP]

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Raphaelle.

          You can instead use [code=mysql]AND `age` <> ''[/code].

          Comment

          • Phaelle
            New Member
            • Jun 2007
            • 10

            #6
            It works!! thanks a lot for the tip

            Comment

            Working...