SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display item only if there's data in a database table cell

    I want to replace a variable named $TCC with a comma only if there's data in a database table field named NameComma2. I tried the switch and IF statement below without success. Can someone help me?

    Thanks.

    PHP Code:
    switch ( $row['NameComma2'] )
    {
      case !=
    '':
      
    $TCC ',';
      break;
      default:
      
    $TCC '';
      break;
    }

    if(
    $row['NameComma2'] !=''):
      
    $TCC ',';
    endif; 

  2. #2
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $TCC = ($row['NameComma2']) ? ',' '';
    //OR 
    $TCC = (! empty($row['NameComma2'])) ? ',' ''
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ruchit
    PHP Code:
    $TCC = ($row['NameComma2']) ? ',' '';
    //OR 
    $TCC = (! empty($row['NameComma2'])) ? ',' ''
    Thanks, but neither of those seems to work for me. I tested my variable with this line:

    PHP Code:
    $TCC ','
    ...and the field NameComma2 displays information in my table, so I'm not sure what I'm doing wrong.

    PHP Code:
    $TCC = ($row['NameComma2']) ? ',' '';
    $TCC = (! empty($row['NameComma2'])) ? '' ','


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
  •