www.webdeveloper.com
Results 1 to 7 of 7

Thread: how to count non empty cells in a row

  1. #1
    Join Date
    May 2008
    Posts
    298

    how to count non empty cells in a row

    Hello, in mysql, how do you count the non empty cells in one row? And I want to count the cells between certain columns only, say between columns 3-10. not all the columns... again, in that row only.

  2. #2
    Join Date
    Mar 2007
    Posts
    946
    Are you talking about wanting to add the values in the column together. You could do this.

    PHP Code:
    select (column1 column2from table 

  3. #3
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    I don't think you can do that using SQL only.
    You will need to fetch the row array and count the empty cells in the array

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    you can use a case statement, but you need 1 case statement for each column you want to look at.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    Quote Originally Posted by chazzy View Post
    you can use a case statement, but you need 1 case statement for each column you want to look at.
    I suggested something similar using IF() over here. Do you think that would work?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Quote Originally Posted by NogDog View Post
    I suggested something similar using IF() over here. Do you think that would work?
    Functionally, it should be equivalent. Performance wise, I can't comment which would be faster. IFNULL wouldn't apply in this case since it returns expr1 if it's not null.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    May 2008
    Posts
    298
    okay it is resolved...thanks to all...i chose to pursue nedal's suggestion, since I already had the array, and consequently here is the code:

    //array is coming from the table by fetch array.

    $kkk = array(0,$q1,$q2,$q3,$q4,$q5,$q6,$q7,$q8);

    for($i=1; $kkk[$i]!=null; $i++)

    {
    some other code
    }

    $qtotal=$i-1;

    //qtotal represents the number of non empty $q in that row.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles