Random spaces appearing?

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
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Random spaces appearing?

Post by tommy1987 »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi there, Im coding a basic blog type page and what is happening is depending on how many blog entries there are a space is being displayed above the table.
Hence, Welcome to .....'s Blog is being displayed then the amount of random new lines, and then the table starts containing the blog entries. It must be something to do with the while loop because the amount of new lines is relevant to how many posts there are. Everything else appears excatly how it should, e.g. the table with the blog entries.

 here is a snippet:

Code: Select all

?>				<tr>
					<td><b>Welcome to <?php echo $name; ?>'s Blog! </b><br/></td>
					<td align="right"><img src="<?=$imgurl?>" class="imgborder" /></td>
				</tr>
				<tr>
					<td colspan="2" valign="top">
					<!--Main Content
					Displaying last 
					<form>
					<select name="nodisp">
					  <option>10</option>
					  <option>20</option>
					  <option>30</option>
					  <option>All</option>
					  </select>
					  </form>
					 entries:
					 -->
					<?php
					$query = "SELECT * from $table";
					$result = mysql_query($query);
										$i = 0;
					while ($row = mysql_fetch_array($result)) {
						if($i != 0) {
    					echo "<tr><td align='center' bgcolor='99CCFF' class='tblhead' style='border-top:solid 1px gray;'><b>".$row[$title]."</b> (".$row[$date].")</td></tr><br>\n";							
						} else /* first one */ {
						echo '<table align="center" class="nametbl" cellspacing="0" width="95%">';
    					echo "<tr><td align='center' bgcolor='99CCFF' class='tblhead'><b>".$row[$title]."</b> (".$row[$date].")</td></tr><br>\n";							
						}
						echo "<tr><td class='blog'>".$row[$body]."</td></tr>";
						if($row[$imgsrc] != "")
						{						
						echo "<tr><td class='blog'><img src=\"$row[$imgsrc]\" alt=\"$row[$imgsrc]\"></td></tr>";
						}
						echo "<td><tr> </tr></td>";
						$i++;
					}
					?>
Hope someone can help this rather annoying problem..


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, I didn't see something in the code. After seeing it in PHP, I might start by doing something like this...

Code: Select all

                          <tr>
                                        <td><b>Welcome to <?php echo $name; ?>s Blog! </b><br/></td>
                                        <td align="right"><img src="<?php echo $imgurl; ?>" class="imgborder" /></td>
                                </tr>
                                <tr>
                                        <td colspan="2" valign="top">
                                        <!--Main Content
                                        Displaying last
                                        <form>
                                        <select name="nodisp">
                                          <option>10</option>
                                          <option>20</option>
                                          <option>30</option>
                                          <option>All</option>
                                          </select>
                                          </form>
                                         entries:
                                         -->
                                        <?php
                                        $query = "SELECT * from $table";
                                        $result = mysql_query($query);
                                        $i = 0;
                                        while ($row = mysql_fetch_array($result)) {
                                                if($i == 0) { 
                                                echo '<table align="center" class="nametbl" cellspacing="0" width="95%">';
                        echo "<tr><td align='center' bgcolor='99CCFF' class='tblhead'><b>".$row[$title]."</b> (".$row[$date].")</td></tr><br>\n";                     
                                                } else  {
                        echo "<tr><td align='center' bgcolor='99CCFF' class='tblhead' style='border-top:solid 1px gray;'><b>".$row[$title]."</b> (".$row[$date].")</td></tr><br>\n";                                                       
                                                }
                                                echo "<tr><td class='blog'>".$row[$body]."</td></tr>";
                                                if($row[$imgsrc] != "")
                                                {                                          
                                                echo "<tr><td class='blog'><img src=\"$row[$imgsrc]\" alt=\"$row[$imgsrc]\"></td></tr>";
                                                }
                                                echo "<td><tr> </tr></td>";
                                                $i++;
                                        }
                                        ?>
Last edited by RobertGonzalez on Fri May 26, 2006 3:09 pm, edited 1 time in total.
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Post by tommy1987 »

No its loops for both because there is an else clause
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Post by tommy1987 »

the problem has been sorted. It was the <br> tags that were causing the problem. Thanks anyway!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

tommy1987 wrote:No its loops for both because there is an else clause
Darnit, you replied before I could edit. I didn't see the else when it was wrapped in code. When it was wrapped in PHP then it stood out. I edited my original response. Sorry about that.
Post Reply