SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Fionnphort, Isle of Mull, Scotland
    Posts
    334
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Selecting only fields from a row that are not blank

    I have a database table where up to 50% of the fields in any row may be blank or NULL. The blank fields vary from row to row. The contents of the fields are strings. I want to obtain a PHP array containing the strings from a row.

    I could, I suppose, create the array from all the fields and then weed out the blanks, but I wonder if there's a way in MySQL to SELECT only those fields with content. I can't name the fields in the query because I don't know in advance which row will selected and so don't know which fields won't be blank.
    Tim Dawson
    Isle of Mull, Scotland

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by ramasaig View Post
    I could, I suppose, create the array from all the fields and then weed out the blanks...
    yes

    Quote Originally Posted by ramasaig View Post
    ... but I wonder if there's a way in MySQL to SELECT only those fields with content.
    no
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Fionnphort, Isle of Mull, Scotland
    Posts
    334
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you, Rudy. I've spent the minutes since I posted my thread working out how to extract the non-blank fields with PHP, and it works a treat.
    Tim Dawson
    Isle of Mull, Scotland

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    glad to help
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •