php adding empty rows/spacing???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slaterino
Forum Commoner
Posts: 46
Joined: Fri Jul 11, 2008 10:50 am

php adding empty rows/spacing???

Post 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
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Re: php adding empty rows/spacing???

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php adding empty rows/spacing???

Post 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.
slaterino
Forum Commoner
Posts: 46
Joined: Fri Jul 11, 2008 10:50 am

Re: php adding empty rows/spacing???

Post 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!
Post Reply