Page 1 of 1

php adding empty rows/spacing???

Posted: Sun Aug 17, 2008 1:54 pm
by slaterino
I have created a CMS section for my site but for some reason am finding that empty rows are being added to the page. Whenever I add a new item in the CMS page the content will move down the page a fraction. On the pages where I have a number of items displayed there is therefore a massive gap between the header and the start of the content. Does anyone know what could cause this? I've included the coding below for everything that is within the content section. It would be really good to know what causes things like this.

Code: Select all

   <div id="content">
<table width="470">
<tr valign="top"><td width="290"><div align="center"><strong>TITLE</strong></div></td><td width="180"><div align="center"><strong>ACTION</strong></div></td></tr>
<?php
 
include("../lib/config.php");
        $result = mysql_query("SELECT * FROM suppliers_uk ORDER BY name ASC",$connect);
        while($myrow = mysql_fetch_array($result))
             {
               echo "<tr><td><b>";
               echo $myrow['name'];
               echo "</b><br />";
               echo $myrow['description'];
               echo "</td><td><br /><a href=\"read_more.php?id=$myrow[id]\">Read More</a>
                | <a href=\"edit.php?id=$myrow[id]\">Edit</a>
                 | <a href=\"delete.php?id=$myrow[id]\">Delete</a></td></tr><br />";
             }
?>
</table>
<br /><br />
      <div align="center">
        <a href=index.php>Home</a> | <a href=add.php>Add Supplier</a> 
      </div>
    </div>
Cheers
Russ

Re: php adding empty rows/spacing???

Posted: Sun Aug 17, 2008 3:55 pm
by neophyte
Well the close ?> php tag consitutes a line break if I'm not mistaken. So that might be messing with your beauty of your html source.

Re: php adding empty rows/spacing???

Posted: Sun Aug 17, 2008 4:10 pm
by califdon
neophyte wrote:Well the close ?> php tag consitutes a line break if I'm not mistaken. So that might be messing with your beauty of your html source.
No, that's not correct.

First of all, I'm surprised it's giving you any output at all. In your several HTML hyperlinks, you are using invalid syntax. Within double quotes, PHP interprets single-value variables, but not arrays, unless you enclose them with curly brackets. The common practice is to end the string and use concatenation, like this:

Code: Select all

echo "</td><td><br /><a href=\"read_more.php?id=" . $myrow['id'] . "\">Read More</a>";
Now I don't see where that would introduce extra line spacing in your output, but I would sure correct it.

In addition, the index for an array must be in quotes, as above.

If you correct those errors and are still having problems, I would suggest that you examine the Source page in your browser, to see what kind of HTML is being generated. If there is extra space on the browser display, it must be caused by some kind of HTML syntax, and if you know what that is, you can trace where it's coming from in your PHP.

Re: php adding empty rows/spacing???

Posted: Sun Aug 17, 2008 5:47 pm
by slaterino
Cheers for that. Have amended the code so that it's now correct. I found it was one of the line breaks which was causing the empty space at the start. Thanks for your help!