Page 1 of 1

Random spaces appearing?

Posted: Fri May 26, 2006 3:00 pm
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]

Posted: Fri May 26, 2006 3:04 pm
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++;
                                        }
                                        ?>

Posted: Fri May 26, 2006 3:09 pm
by tommy1987
No its loops for both because there is an else clause

Posted: Fri May 26, 2006 3:12 pm
by tommy1987
the problem has been sorted. It was the <br> tags that were causing the problem. Thanks anyway!

Posted: Fri May 26, 2006 3:15 pm
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.