SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select cell from row, dont display if cell has no value - help!

    Hi,

    I have the following script....pretty simple
    PHP Code:
    <?php

    include("dbconnect.php");
    $query "SELECT text14 FROM questions";
    $result mysql_query($query);
    ?>
    <html>
    <head>
    <title>How can we improve paddypower.com?</title>
    <style>
    td{font-family:arial;font-size:10pt}
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <table width="760" border="1" cellspacing="0" cellpadding="5" align="center" bordercolor="#000000">
      <tr> 
        <td><b><font color="#FF0000">How can we improve paddypower.com?</font></b></td>
      </tr>
      <tr>
        <td>
        <!-- display details loop-->
        <?php
        
    while($row mysql_fetch_array($result)){
        
    ?>
          <table width="100%" border="0" cellspacing="0" cellpadding="5">
            <tr> 
              <td width="21%" bgcolor="#FFFFCC"><b>Feedback:</b></td>
              <td width="79%"><? echo $row[text14]?></td>
            </tr>
          </table>
          <hr width="100%" noshade align="center">
          <?php ?>
          <!-- display details loop end -->
        </td>
      </tr>
    </table>
    </body>
    </html>
    This basically displaus whatever is in the cell text14 in the database. However, there are 13 other cells in each row. Not all of these cells have a value (text14 doesnt always have a value)

    When i run the script above, it loops through every row and displays a blank cell if there is no value in text14 for that row. How can I make it work so that only text14 cells that have a value are displayed, regardless of whatever value are in other rows.

    Thanks,
    Martin

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: select cell from row, dont display if cell has no value - help!

    PHP Code:
    $query 'SELECT text14 FROM questions WHERE text14 IS NOT NULL'
    http://www.mysql.com/doc/en/Problems_with_NULL.html
    In SQL, the NULL value is always false in comparison to any other value, even NULL. An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for the operators and functions involved in the expression.

    ...

    To look for NULL values, you must use the IS NULL test. The following shows how to find the NULL phone number and the empty phone number:

    ...

    To help with NULL handling, you can use the IS NULL and IS NOT NULL operators and the IFNULL() function.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


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
  •