Results 1 to 3 of 3

Thread: Take out the space when a field is displayed that is empty

  1. #1
    Join Date
    Dec 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Take out the space when a field is displayed that is empty

    Hello,

    I have posted the code I am using below. I have researched and researched to try and find out how to take out blank rows when certain fields are empty.

    For example if I am doing a page that displays information about a company and some of them do have website addresses and some of them do not, then I do not want there to be a blank white space when the page is displayed.

    Is there anyone who can help me with the code and where exactly I would place it. Everything I have tried either returns an error or takes the field out on every record (even the ones that are not blank). Thank you.

    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }

    $maxRows_rsvendors = 10;
    $pageNum_rsvendors = 0;
    if (isset($_GET['pageNum_rsvendors'])) {
    $pageNum_rsvendors = $_GET['pageNum_rsvendors'];
    }
    $startRow_rsvendors = $pageNum_rsvendors * $maxRows_rsvendors;

    $varzip_rsvendors = "1";
    if (isset($_POST['Zip'])) {
    $varzip_rsvendors = $_POST['Zip'];
    }
    $varcategory_rsvendors = "1";
    if (isset($_POST['Category'])) {
    $varcategory_rsvendors = $_POST['Category'];
    }
    mysql_select_db($database_connect, $connect);
    $query_rsvendors = sprintf("SELECT commercial.Company_Name, commercial.Contact_fname, commercial.Contact_lname, commercial.Title, commercial.Street, commercial.City, commercial.`State`, commercial.Zip, commercial.Phone, commercial.Website, commercial.Email, commercial.Category, commercial.Photo, commercial.About, commercial.ID FROM commercial WHERE commercial.Zip=%s AND commercial.Category=%s ", GetSQLValueString($varzip_rsvendors, "text"),GetSQLValueString($varcategory_rsvendors, "text"));
    $query_limit_rsvendors = sprintf("%s LIMIT %d, %d", $query_rsvendors, $startRow_rsvendors, $maxRows_rsvendors);
    $rsvendors = mysql_query($query_limit_rsvendors, $connect) or die(mysql_error());
    $row_rsvendors = mysql_fetch_assoc($rsvendors);

    if (isset($_GET['totalRows_rsvendors'])) {
    $totalRows_rsvendors = $_GET['totalRows_rsvendors'];
    } else {
    $all_rsvendors = mysql_query($query_rsvendors);
    $totalRows_rsvendors = mysql_num_rows($all_rsvendors);
    }
    $totalPages_rsvendors = ceil($totalRows_rsvendors/$maxRows_rsvendors)-1;
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    <link href="vol.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    <!--
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    body {
    margin-top: 0px;
    margin-left: 0px;
    margin-right: 0px;
    }
    #topcoloredline {
    background-color: #990000;
    }
    #container {
    background-color: #FFFFFF;
    background-image: none;
    background-repeat: no-repeat;
    background-position: bottom;
    }
    #container #header {
    background-color: #990000;
    }
    #topbar {
    background-image: url(images/top_bar_red.jpg);
    background-repeat: repeat-x;
    }
    #container #middlehome {
    height: 162px;
    }
    h3 {
    font-size: 10px;
    }
    #container #interiorform {
    }
    .style1 {
    color: #000000;
    font-size: 12px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-weight: lighter;
    }
    #apDiv1 {
    position:absolute;
    left:212px;
    top:233px;
    width:479px;
    height:144px;
    z-index:1;
    }
    #apDiv2 {
    position:absolute;
    left:176px;
    top:308px;
    width:669px;
    height:105px;
    z-index:1;
    }
    -->
    </style>
    <script type="text/javascript">
    <!--
    function MM_reloadPage(init) { //reloads the window if Nav4 resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    //-->
    </script>
    </head>

    <body>

    <div id="topbar"></div>

    <div id="container">
    <?php if ($totalRows_rsvendors == 0) { // Show if recordset empty ?>
    <!--end of ap div for no records found -->
    <?php } // Show if recordset empty ?>
    <div id="header">
    <div id="tagline">
    <h1>Home of the Best Vendors in the Known Universe</h1>
    </div>
    <div id="logo"><img src="images/red_vol_logo.jpg" alt="vendor online logo" width="222" height="129" hspace="5" /></div>
    </div><!-- end #header -->
    <!-- end #middle home -->
    <div id="interiorform">
    <table width="91%" border="0" align="center">

    <?php do { ?>

    <tr align="left" valign="middle">
    <td colspan="3" class="style1"><img src="images/black_bar.jpg" alt="blackbar" width="680" height="17" /></td>
    </tr>
    <tr align="left" valign="middle">
    <td width="20%" rowspan="7" align="left" valign="top" class="style1"><img src="images/<?php echo $row_rsvendors['Photo']; ?>" /></td>
    <td width="39%" class="style1"><span class="style1"><?php echo $row_rsvendors['Company_Name']; ?></span></td>
    <td width="41%" rowspan="7" align="center" valign="top" class="style1"><?php if ($totalRows_rsvendors > 0) { // Show if recordset not empty ?>
    <table width="230" height="95" border="1" align="center" bordercolor="#333333">
    <tr>
    <td align="left" valign="top" class="style1"><?php echo $row_rsvendors['About']; ?> <br />
    <br /></td>
    </tr>
    </table>
    <?php } // Show if recordset not empty ?>
    </td>
    </tr>
    <tr>
    <td align="left" valign="middle" class="style1">

    <?php echo $row_rsvendors['Contact_fname']; ?>&nbsp;<?php echo $row_rsvendors['Contact_lname']; ?>&nbsp;<?php echo $row_rsvendors['Title']; ?></td>
    </tr>

    <tr align="left" valign="middle">
    <td class="style1"><?php echo $row_rsvendors['Street']; ?></td>
    </tr>
    <tr align="left" valign="middle">
    <td class="style1"><?php echo $row_rsvendors['City']; ?>
    <?php if ($totalRows_rsvendors > 0) { // Show if recordset not empty ?>
    ,
    <?php } // Show if recordset not empty ?>
    &nbsp;<?php echo $row_rsvendors['State']; ?>&nbsp;&nbsp;<?php echo $row_rsvendors['Zip']; ?></td>
    </tr>

    <tr align="left" valign="middle">
    <td class="style1"><?php echo $row_rsvendors['Phone']; ?></td>
    </tr>
    <tr align="left" valign="middle">
    <td class="style1"><a href="<?php echo $row_rsvendors['Website']; ?>">
    <?php
    echo $row_rsvendors['Website']; ?></a></td>
    </tr>
    <tr align="left" valign="middle">
    <td class="style1"><?php echo $row_rsvendors['Email']; ?></td>
    </tr>


    <?php } while ($row_rsvendors = mysql_fetch_assoc($rsvendors)); ?>
    </table>

    <?php if ($totalRows_rsvendors == 0) { // Show if recordset empty ?>
    <div align="center"><img src="images/no-records-found.jpg" alt="no records found" width="600" height="100" border="0" usemap="#searchagain" />
    <map name="searchagain" id="searchagain">
    <area shape="rect" coords="19,16,161,82" href="index.html" />
    <area shape="rect" coords="290,44,443,66" href="commercial_vendors.php" />
    </map>
    </div>
    <?php } // Show if recordset empty ?>

    </div>
    <!-- end #interiorform -->

    </div><!-- end #container -->

    <div id="interiorfooter">
    <?php if ($totalRows_rsvendors > 0) { // Show if recordset not empty ?>
    <img src="images/results_page_footer.jpg" width="700" height="80" border="0" usemap="#commercialvendors" />
    <?php } // Show if recordset not empty ?>
    <map name="commercialvendors" id="commercialvendors">
    <area shape="rect" coords="58,107,100,123" href="index.html" />
    <area shape="rect" coords="111,105,184,122" href="commercial_vendors.php" />
    <area shape="rect" coords="339,9,685,40" href="index.html" />
    <area shape="rect" coords="31,53,73,70" href="index.html" />
    <area shape="rect" coords="86,54,156,71" href="commercial_vendors.php" />
    </map>
    <!-- end #interiorfooter footer -->
    </div>
    <!-- end #interiorfooter -->
    </body>
    </html>
    <?php
    mysql_free_result($rsvendors);
    ?>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Simple example:

    Code:
    <?php if ($row_rsvendors['Website'] != '') { ?>
    <tr align="left" valign="middle">
    <td class="style1"><a href="<?php echo $row_rsvendors['Website']; ?>">
    <?php
    echo $row_rsvendors['Website']; ?></a></td>
    </tr>
    <?php } ?>

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Dec 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This worked so great!
    I can not tell you how much I appreciate it.

    Thank you!

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
  •